Commit d2e0fad5 authored by Noel Alonso's avatar Noel Alonso
Browse files

Añade excepción para url inválida

parent 7411d995
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ public enum ExceptionType implements ExceptionTypeItfc {
	
	INTERNAL_EXCEPTION(Constants.INTERNAL_EXCEPTION),
	RESOURCE_NOT_FOUND(Constants.RESOURCE_NOT_FOUND),
	URL_EXCEPTION(Constants.URL_EXCEPTION),
	
	// Data
	DT_INCCORRECT_INTERVAL(Constants.DT_INCCORRECT_INTERVAL),
@@ -241,6 +242,7 @@ public enum ExceptionType implements ExceptionTypeItfc {
			
			INTERNAL_EXCEPTION = "InternalException",
			RESOURCE_NOT_FOUND = "ResourceNotFound",
			URL_EXCEPTION = "URLException",
			
			// Data
			DT_INCCORRECT_INTERVAL = "IncorrectInterval",
+43 −0
Original line number Diff line number Diff line
package es.redmic.exception.custom;

/*-
 * #%L
 * Exceptions
 * %%
 * Copyright (C) 2019 REDMIC Project / Server
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import java.util.Arrays;

import es.redmic.exception.common.ExceptionType;
import es.redmic.exception.common.NotFoundException;

public class URLException extends NotFoundException {

	private static final long serialVersionUID = 6714485190161856195L;

	public URLException(Exception e, String url) {

		super(ExceptionType.URL_EXCEPTION, e);
		setFieldErrors(Arrays.asList(url));
	}

	public URLException(String url) {

		super(ExceptionType.URL_EXCEPTION);
		setFieldErrors(Arrays.asList(url));
	}
}
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ InvalidAphia=Trying to update a taxon with aphia {0}. Ahpia does not exist in wo
#Common exception messages
InternalException=An error occurred while processing the request.
ResourceNotFound=The resource you are trying to access does not exist or is not available.
URLException=URL {0} is not valid.

#Database exception messages
DBConstraintViolation=Error, data constraint violation. {0}
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ InvalidAphia=Intentando actualizar un tax
#Common exception messages
InternalException=Se ha producido un error al procesar la petición. Inténtelo más tarde.
ResourceNotFound=El recurso al que está intentando acceder no existe o no está disponible.
URLException=URL {0} no es válida

#Database exception messages
DBConstraintViolation=Error, violación de una reestricción de los datos. {0}
+48 −0
Original line number Diff line number Diff line
package es.redmic.test.unit.exception.custom;

/*-
 * #%L
 * Exceptions
 * %%
 * Copyright (C) 2019 REDMIC Project / Server
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import java.io.IOException;
import java.util.Arrays;

import org.junit.Test;

import es.redmic.exception.common.ExceptionType;
import es.redmic.exception.custom.URLException;
import es.redmic.test.unit.exception.common.BaseExceptionTest;

public class URLExceptionTest extends BaseExceptionTest {

	String url = "ht://www.marinespecies.org/rest/AphiaClassificationByAphiaID/3";

	@Test
	public void checkPattern_IsEqualToMessage_WhenNoLocaleSet() throws IOException {

		checkMessage(new URLException(url), ExceptionType.URL_EXCEPTION.toString(), Arrays.asList(url));
	}

	@Test
	public void checkPattern_IsEqualToMessage_WhenNoLocaleSetAndSendException() throws IOException {

		checkMessage(new URLException(new Exception(), url), ExceptionType.URL_EXCEPTION.toString(),
				Arrays.asList(url));
	}
}