/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019, 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
this(statusCode, message, exception, null);
}
+ /**
+ * Instantiates a new model runtime exception from a PfModelException instance.
+ *
+ * @param exception the exception that caused this model exception
+ */
+ public PfModelRuntimeException(final PfModelException exception) {
+ super(exception.getMessage(), exception);
+ this.object = exception.getObject();
+ errorResponse.setResponseCode(exception.getErrorResponse().getResponseCode());
+ ErrorResponseUtils.getExceptionMessages(errorResponse, this);
+ }
+
/**
* Instantiates a new model runtime exception.
*
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* @param defaultValue value to be returned if source is {@code null}
* @return a new map, containing mappings of all of the items in the original map
*/
- public static <T, R> Map<String, R> mapMap(Map<String, T> source, Function<T, R> mapFunc,
- Map<String, R> defaultValue) {
+ public static <K, T, R> Map<K, R> mapMap(Map<K, T> source, Function<T, R> mapFunc,
+ Map<K, R> defaultValue) {
if (source == null) {
return defaultValue;
}
- Map<String, R> map = new LinkedHashMap<>();
- for (Entry<String, T> ent : source.entrySet()) {
+ Map<K, R> map = new LinkedHashMap<>();
+ for (Entry<K, T> ent : source.entrySet()) {
map.put(ent.getKey(), mapFunc.apply(ent.getValue()));
}
* @return a new map, containing mappings of all of the items in the original map, or {@code null} if the source is
* {@code null}
*/
- public static <T, R> Map<String, R> mapMap(Map<String, T> source, Function<T, R> mapFunc) {
+ public static <K, T, R> Map<K, R> mapMap(Map<K, T> source, Function<T, R> mapFunc) {
return mapMap(source, mapFunc, null);
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.io.IOException;
import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import org.junit.Test;
import org.onap.policy.models.errors.concepts.ErrorResponse;
assertEquals("Runtime Message\nIO runtime exception message",
String.join("\n", errorResponse.getErrorDetails()));
assertEquals(key, re.getObject());
+
+ PfModelRuntimeException pfre = new PfModelRuntimeException(ae);
+ assertEquals(ae.getErrorResponse().getResponseCode(), pfre.getErrorResponse().getResponseCode());
+ assertEquals(ae.getMessage(), pfre.getMessage());
+
+ try {
+ try {
+ throw new PfModelException(Status.BAD_GATEWAY, "An Exception");
+ } catch (PfModelException pfme) {
+ throw new PfModelRuntimeException(pfme);
+ }
+ } catch (PfModelRuntimeException pfmre) {
+ assertEquals(Status.BAD_GATEWAY, pfmre.getErrorResponse().getResponseCode());
+ assertEquals("An Exception", pfmre.getMessage());
+ assertEquals(PfModelException.class.getName(), pfmre.getCause().getClass().getName());
+ }
}
}