aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-common/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'mso-api-handlers/mso-api-handler-common/src/test/java/org')
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/RequestClientTest.java60
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/filters/RequestIdFilterTest.java80
2 files changed, 119 insertions, 21 deletions
diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/RequestClientTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/RequestClientTest.java
new file mode 100644
index 0000000000..86b12ae8f6
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/RequestClientTest.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (c) 2019 Samsung. 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.
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.apihandler.common;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class RequestClientTest {
+
+ private static final String ENCRYPTION_KEY = "aa3871669d893c7fb8abbcda31b88b4f";
+
+ private RequestClient requestClient;
+
+ @Before
+ public void init() {
+ requestClient = Mockito.mock(RequestClient.class, Mockito.CALLS_REAL_METHODS);
+ }
+
+ @Test
+ public void getEncryptedPropValueWithSuccess() {
+
+ String encryptedValue = requestClient.getEncryptedPropValue(
+ "E8E19DD16CC90D2E458E8FF9A884CC0452F8F3EB8E321F96038DE38D5C1B0B02DFAE00B88E2CF6E2A4101AB2C011FC161212EE",
+ "defaultValue", ENCRYPTION_KEY);
+
+ Assert.assertEquals("apihBpmn:camunda-R1512!", encryptedValue);
+ }
+
+ @Test
+ public void getDefaultEncryptedPropValue() {
+
+ String encryptedValue =
+ requestClient.getEncryptedPropValue("012345678901234567890123456789", "defaultValue", ENCRYPTION_KEY);
+
+ Assert.assertEquals("defaultValue", encryptedValue);
+ }
+
+}
diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/filters/RequestIdFilterTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/filters/RequestIdFilterTest.java
index 6c674db9f4..8716047603 100644
--- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/filters/RequestIdFilterTest.java
+++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/filters/RequestIdFilterTest.java
@@ -1,66 +1,104 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 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.
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.apihandler.filters;
-import static org.junit.Assert.assertEquals;
+import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.doReturn;
import java.io.IOException;
+import java.util.Collections;
import javax.ws.rs.container.ContainerRequestContext;
-import org.apache.http.HttpStatus;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.Mockito;
import org.mockito.Spy;
-import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoJUnitRunner;
-import org.mockito.junit.MockitoRule;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.onap.so.apihandlerinfra.exceptions.DuplicateRequestIdException;
import org.onap.so.db.request.beans.InfraActiveRequests;
import org.onap.so.db.request.client.RequestsDbClient;
+import org.onap.so.serviceinstancebeans.RequestError;
+import org.onap.so.serviceinstancebeans.ServiceException;
import org.slf4j.MDC;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
@RunWith(MockitoJUnitRunner.class)
public class RequestIdFilterTest {
@Mock
- ContainerRequestContext mockContext;
+ private ContainerRequestContext mockContext;
@Mock
- protected RequestsDbClient requestsDbClient;
+ private RequestsDbClient requestsDbClient;
@InjectMocks
@Spy
- RequestIdFilter requestIdFilter;
+ private RequestIdFilter requestIdFilter;
@Rule
public ExpectedException thrown = ExpectedException.none();
- @Rule
- public MockitoRule mockitoRule = MockitoJUnit.rule();
+ private static final String REQUEST_ID = "32807a28-1a14-4b88-b7b3-2950918aa769";
+ private ObjectMapper mapper = new ObjectMapper();
- @Test
- public void filterTest() throws IOException {
+ private RequestError getRequestError() throws IOException {
+ RequestError requestError = new RequestError();
+ mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false);
+ ServiceException serviceException = new ServiceException();
+ serviceException.setMessageId("SVC0002");
+ serviceException.setText(
+ "RequestId: 32807a28-1a14-4b88-b7b3-2950918aa769 already exists in the RequestDB InfraActiveRequests table");
+ serviceException.setVariables(Collections.emptyList());
+ requestError.setServiceException(serviceException);
+ return requestError;
+ }
- String requestId = "32807a28-1a14-4b88-b7b3-2950918aa769";
+ @Test
+ public void filterTestInfra() throws IOException {
+ String error = mapper.writeValueAsString(getRequestError());
+ String requestId = REQUEST_ID;
MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId);
// ExpectedRecord InfraActiveRequests
InfraActiveRequests infraActiveRequests = new InfraActiveRequests();
- infraActiveRequests.setRequestStatus("FAILED");
- infraActiveRequests.setProgress(100L);
- infraActiveRequests.setLastModifiedBy("APIH");
- infraActiveRequests.setRequestScope("network");
- infraActiveRequests.setRequestAction("deleteInstance");
- infraActiveRequests.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa769");
+ infraActiveRequests.setRequestId(REQUEST_ID);
doReturn(infraActiveRequests).when(requestsDbClient).getInfraActiveRequestbyRequestId(requestId);
+ doReturn(error).when(requestIdFilter).createRequestError(REQUEST_ID, "InfraActiveRequests");
+ thrown.expect(DuplicateRequestIdException.class);
+ thrown.expectMessage("HTTP 400 Bad Request");
requestIdFilter.filter(mockContext);
+ }
- Mockito.verify(requestIdFilter, Mockito.times(1)).filter(mockContext);
- assertEquals(MDC.get(ONAPLogConstants.MDCs.RESPONSE_CODE), String.valueOf(HttpStatus.SC_BAD_REQUEST));
+ @Test
+ public void createRequestErrorTest() throws IOException {
+ RequestError requestError = getRequestError();
+ String result = requestIdFilter.createRequestError(REQUEST_ID, "InfraActiveRequests");
+ RequestError resultingError = mapper.readValue(result, RequestError.class);
+ assertThat(resultingError, sameBeanAs(requestError));
}
}