-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017 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=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- */
-package org.onap.aai.rest;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.when;
-
-import java.io.IOException;
-
-import javax.ws.rs.core.Response;
-
-import org.apache.commons.lang3.StringUtils;
-import org.junit.Test;
-import org.onap.aai.introspection.Version;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
-public class BulkProcessConsumerTest extends BulkProcessorTestAbstraction {
-
- private static final EELFLogger logger = EELFManager.getInstance().getLogger(BulkProcessConsumerTest.class.getName());
-
-
- @Test
- public void bulkAddPayloadInBulkProcessTest() throws IOException {
-
- when(uriInfo.getPath()).thenReturn(uri);
- when(uriInfo.getPath(false)).thenReturn(uri);
-
- String payload = getBulkPayload("pserver-transactions");
- Response response = executeRequest(payload);
-
- assertEquals("Valid Response Code", Response.Status.CREATED.getStatusCode(), response.getStatus());
- assertEquals("Contains 3 {\"201\":null}", 3, StringUtils.countMatches(response.getEntity().toString(), "{\"201\":null}"));
- }
-
- @Test
- public void bulkProcessPayloadTest() throws IOException {
-
- when(uriInfo.getPath()).thenReturn(uri);
- when(uriInfo.getPath(false)).thenReturn(uri);
-
- String payload = getBulkPayload("pserver-bulk-process-transactions");
- Response response = executeRequest(payload);
-
- assertEquals("Valid Response Code", Response.Status.CREATED.getStatusCode(), response.getStatus());
- assertEquals("Contains 1 {\"201\":null}", 1, StringUtils.countMatches(response.getEntity().toString(), "{\"201\":null}"));
- assertEquals("Contains 1 {\"404\":\"{", 1, StringUtils.countMatches(response.getEntity().toString(), "{\"404\":\"{"));
- assertEquals("Contains 1 ERR.5.4.6114", 1, StringUtils.countMatches(response.getEntity().toString(), "ERR.5.4.6114"));
- }
-
- @Test
- public void bulkProcessComplexDeletePayloadTest() throws IOException {
-
- when(uriInfo.getPath()).thenReturn(uri);
- when(uriInfo.getPath(false)).thenReturn(uri);
-
- String payload = getBulkPayload("complex-bulk-process-transactions");
- Response response = executeRequest(payload);
-
- System.out.println(response.getEntity().toString());
- assertEquals("Valid Response Code", Response.Status.CREATED.getStatusCode(), response.getStatus());
- assertEquals("Contains 0 {\"201\":null}", 0, StringUtils.countMatches(response.getEntity().toString(), "{\"201\":null}"));
- assertEquals("Contains 1 {\"404\":\"{", 1, StringUtils.countMatches(response.getEntity().toString(), "{\"404\":\"{"));
- assertEquals("Contains 1 ERR.5.4.6114", 1, StringUtils.countMatches(response.getEntity().toString(), "ERR.5.4.6114"));
- }
-
-
- @Test
- public void bulkAddInvalidMethodTest() throws IOException {
-
- when(uriInfo.getPath()).thenReturn(uri);
- when(uriInfo.getPath(false)).thenReturn(uri);
-
- String payload = getBulkPayload("pserver-transactions-invalid-method");
- Response response = executeRequest(payload);
-
- assertEquals("Valid Response Code", Response.Status.CREATED.getStatusCode(), response.getStatus());
- assertEquals("Contains 1 {\"400\":\"{", 1, StringUtils.countMatches(response.getEntity().toString(), "{\"400\":\"{"));
- assertEquals("Contains 1 ERR.5.4.6118", 1, StringUtils.countMatches(response.getEntity().toString(), "ERR.5.4.6118"));
- }
-
- @Test
- public void bulkAddThrowExceptionWhenPayloadContainsNoTransactionsTest(){
-
- when(uriInfo.getPath()).thenReturn(uri);
- when(uriInfo.getPath(false)).thenReturn(uri);
-
- String payload = "{\"transactions\":[]}";
- Response response = executeRequest(payload);
-
- assertEquals("Bad Request", Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- assertEquals("Contains error code", true, response.getEntity().toString().contains("ERR.5.4.6118"));
- }
-
- @Test
- public void bulkAddThrowExceptionWhenInvalidJsonTest() throws IOException {
-
- when(uriInfo.getPath()).thenReturn(uri);
- when(uriInfo.getPath(false)).thenReturn(uri);
-
- String payload = "{";
- Response response = executeRequest(payload);
-
- assertEquals("Bad Request", Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- assertEquals("Contains error code", true, response.getEntity().toString().contains("ERR.5.4.6111"));
- }
-
- @Override
- protected BulkConsumer getConsumer(){
- return new BulkProcessConsumer();
- }
-
- @Override
- protected String getUri() {
- return "/aai/" + Version.getLatest().toString() + "/bulkprocess";
- }
-}
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+package org.onap.aai.rest;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertNotNull;\r
+import static org.mockito.Mockito.when;\r
+\r
+import java.io.IOException;\r
+\r
+import javax.ws.rs.core.Response;\r
+\r
+import org.apache.commons.lang3.StringUtils;\r
+import org.json.JSONException;\r
+import org.junit.Test;\r
+import org.onap.aai.introspection.Version;\r
+import org.skyscreamer.jsonassert.JSONAssert;\r
+\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+\r
+public class BulkProcessConsumerTest extends BulkProcessorTestAbstraction {\r
+\r
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(BulkProcessConsumerTest.class.getName());\r
+ private LegacyMoxyConsumer legacyMoxyConsumer;\r
+\r
+ @Test\r
+ public void bulkAddPayloadInBulkProcessTest() throws IOException {\r
+\r
+ when(uriInfo.getPath()).thenReturn(uri);\r
+ when(uriInfo.getPath(false)).thenReturn(uri);\r
+\r
+ String payload = getBulkPayload("pserver-transactions");\r
+ Response response = executeRequest(payload);\r
+\r
+ assertEquals("Valid Response Code", Response.Status.CREATED.getStatusCode(), response.getStatus());\r
+ assertEquals("Contains 3 {\"201\":null}", 3, StringUtils.countMatches(response.getEntity().toString(), "{\"201\":null}"));\r
+ }\r
+ \r
+ @Test\r
+ public void bulkProcessPayloadTest() throws IOException {\r
+\r
+ when(uriInfo.getPath()).thenReturn(uri);\r
+ when(uriInfo.getPath(false)).thenReturn(uri);\r
+\r
+ String payload = getBulkPayload("pserver-bulk-process-transactions");\r
+ Response response = executeRequest(payload);\r
+\r
+ assertEquals("Valid Response Code", Response.Status.CREATED.getStatusCode(), response.getStatus());\r
+ assertEquals("Contains 1 {\"201\":null}", 1, StringUtils.countMatches(response.getEntity().toString(), "{\"201\":null}"));\r
+ assertEquals("Contains 1 {\"404\":\"{", 1, StringUtils.countMatches(response.getEntity().toString(), "{\"404\":\"{"));\r
+ assertEquals("Contains 1 ERR.5.4.6114", 1, StringUtils.countMatches(response.getEntity().toString(), "ERR.5.4.6114"));\r
+ }\r
+ \r
+ @Test\r
+ public void bulkProcessComplexDeletePayloadTest() throws IOException {\r
+\r
+ when(uriInfo.getPath()).thenReturn(uri);\r
+ when(uriInfo.getPath(false)).thenReturn(uri);\r
+\r
+ String payload = getBulkPayload("complex-bulk-process-transactions");\r
+ Response response = executeRequest(payload);\r
+\r
+ System.out.println(response.getEntity().toString());\r
+ assertEquals("Valid Response Code", Response.Status.CREATED.getStatusCode(), response.getStatus());\r
+ assertEquals("Contains 0 {\"201\":null}", 0, StringUtils.countMatches(response.getEntity().toString(), "{\"201\":null}"));\r
+ assertEquals("Contains 1 {\"404\":\"{", 1, StringUtils.countMatches(response.getEntity().toString(), "{\"404\":\"{"));\r
+ assertEquals("Contains 1 ERR.5.4.6114", 1, StringUtils.countMatches(response.getEntity().toString(), "ERR.5.4.6114"));\r
+ }\r
+ \r
+ @Test\r
+ public void testBulkDeletePserverAndComplexRelationship() throws IOException, JSONException {\r
+ \r
+ legacyMoxyConsumer = new LegacyMoxyConsumer();\r
+\r
+ String pserverData = getPayload("payloads/relationship/pserver-bugfix.json");\r
+ String complexData = getPayload("payloads/relationship/complex-bugfix.json");\r
+\r
+ String hostname = "pserver-9876543210-77-jenkins";\r
+ String physicalLocationId ="complex-987654321-77-jenkins";\r
+\r
+ String pserverUri = String.format("cloud-infrastructure/pservers/pserver/%s", hostname);\r
+ String complexUri = String.format("cloud-infrastructure/complexes/complex/%s", physicalLocationId);\r
+\r
+ doSetupResource(pserverUri, pserverData);\r
+ doSetupResource(complexUri, complexData);\r
+\r
+ String complexToPserverRelationshipData = getPayload("payloads/relationship/pserver-complex-relationship-for-bulk.json");\r
+ String complexToPserverRelationshipUri = String.format(\r
+ "cloud-infrastructure/pservers/pserver/%s/relationship-list/relationship", hostname);\r
+\r
+ Response response = legacyMoxyConsumer.updateRelationship(\r
+ complexToPserverRelationshipData,\r
+ Version.getLatest().toString(),\r
+ complexToPserverRelationshipUri,\r
+ httpHeaders,\r
+ uriInfo,\r
+ null\r
+ );\r
+\r
+ assertNotNull("Response from the legacy moxy consumer returned null", response);\r
+ int code = response.getStatus();\r
+ if(!VALID_HTTP_STATUS_CODES.contains(code)){\r
+ System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity());\r
+ }\r
+\r
+ assertEquals("Expected to return status created from the response",\r
+ Response.Status.OK.getStatusCode(), response.getStatus());\r
+ logger.info("Response Code: " + code + "\tEntity: " + response.getEntity());\r
+\r
+ // TODO - Need to actually verify the relationship between pserver and cloud-region\r
+ \r
+ String payload = getBulkPayload("complex-bulk-process-delete-transactions");\r
+ Response responseBulkDelete = executeRequest(payload);\r
+\r
+ System.out.println(responseBulkDelete.getEntity().toString());\r
+ \r
+ code = responseBulkDelete.getStatus();\r
+ \r
+ if(!VALID_HTTP_STATUS_CODES.contains(code)){\r
+ System.out.println("Response Code: " + code + "\tEntity: " + responseBulkDelete.getEntity());\r
+ System.out.println("Response Code: " + code + "\tEntity: " + responseBulkDelete.getEntity());\r
+ } \r
+ assertEquals("Expected to return status created from the response",\r
+ Response.Status.CREATED.getStatusCode(), responseBulkDelete.getStatus());\r
+ assertEquals("Contains 0 {\"204\":null}", 1, StringUtils.countMatches(responseBulkDelete.getEntity().toString(), "{\"204\":null}"));\r
+ \r
+ }\r
+ \r
+ protected void doSetupResource(String uri, String payload) throws JSONException {\r
+\r
+ when(uriInfo.getPath()).thenReturn(uri);\r
+ when(uriInfo.getPath(false)).thenReturn(uri);\r
+\r
+ Response response = legacyMoxyConsumer.getLegacy(\r
+ "",\r
+ Version.getLatest().toString(),\r
+ uri,\r
+ "all",\r
+ "false",\r
+ httpHeaders,\r
+ uriInfo,\r
+ null\r
+ );\r
+\r
+ assertNotNull("Response from the legacy moxy consumer returned null", response);\r
+ assertEquals("Expected to not have the data already in memory",\r
+ Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());\r
+\r
+ response = legacyMoxyConsumer.update(\r
+ payload,\r
+ Version.getLatest().toString(),\r
+ uri,\r
+ httpHeaders,\r
+ uriInfo,\r
+ null\r
+ );\r
+\r
+ assertNotNull("Response from the legacy moxy consumer returned null", response);\r
+ int code = response.getStatus();\r
+ if(!VALID_HTTP_STATUS_CODES.contains(code)){\r
+ System.out.println("Response Code: " + code + "\tEntity: " + response.getEntity());\r
+ }\r
+ assertEquals("Expected to return status created from the response",\r
+ Response.Status.CREATED.getStatusCode(), response.getStatus());\r
+\r
+ queryParameters.add("depth", "10000");\r
+ response = legacyMoxyConsumer.getLegacy(\r
+ "",\r
+ Version.getLatest().toString(),\r
+ uri,\r
+ "all",\r
+ "false",\r
+ httpHeaders,\r
+ uriInfo,\r
+ null\r
+ );\r
+\r
+ assertNotNull("Response from the legacy moxy consumer returned null", response);\r
+ assertEquals("Expected to return the pserver data that was just put in memory",\r
+ Response.Status.OK.getStatusCode(), response.getStatus());\r
+\r
+ if("".equalsIgnoreCase(payload)){\r
+ payload = "{}";\r
+ }\r
+\r
+ JSONAssert.assertEquals(payload, response.getEntity().toString(), false);\r
+ }\r
+ \r
+ \r
+ @Test\r
+ public void bulkAddInvalidMethodTest() throws IOException {\r
+\r
+ when(uriInfo.getPath()).thenReturn(uri);\r
+ when(uriInfo.getPath(false)).thenReturn(uri);\r
+\r
+ String payload = getBulkPayload("pserver-transactions-invalid-method");\r
+ Response response = executeRequest(payload);\r
+\r
+ assertEquals("Valid Response Code", Response.Status.CREATED.getStatusCode(), response.getStatus());\r
+ assertEquals("Contains 1 {\"400\":\"{", 1, StringUtils.countMatches(response.getEntity().toString(), "{\"400\":\"{"));\r
+ assertEquals("Contains 1 ERR.5.4.6118", 1, StringUtils.countMatches(response.getEntity().toString(), "ERR.5.4.6118"));\r
+ }\r
+\r
+ @Test\r
+ public void bulkAddThrowExceptionWhenPayloadContainsNoTransactionsTest(){\r
+\r
+ when(uriInfo.getPath()).thenReturn(uri);\r
+ when(uriInfo.getPath(false)).thenReturn(uri);\r
+\r
+ String payload = "{\"transactions\":[]}";\r
+ Response response = executeRequest(payload);\r
+\r
+ assertEquals("Bad Request", Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());\r
+ assertEquals("Contains error code", true, response.getEntity().toString().contains("ERR.5.4.6118"));\r
+ }\r
+\r
+ @Test\r
+ public void bulkAddThrowExceptionWhenInvalidJsonTest() throws IOException {\r
+\r
+ when(uriInfo.getPath()).thenReturn(uri);\r
+ when(uriInfo.getPath(false)).thenReturn(uri);\r
+\r
+ String payload = "{";\r
+ Response response = executeRequest(payload);\r
+\r
+ assertEquals("Bad Request", Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());\r
+ assertEquals("Contains error code", true, response.getEntity().toString().contains("ERR.5.4.6111"));\r
+ }\r
+ \r
+ @Override\r
+ protected BulkConsumer getConsumer(){\r
+ return new BulkProcessConsumer();\r
+ }\r
+ \r
+ @Override\r
+ protected String getUri() {\r
+ return "/aai/" + Version.getLatest().toString() + "/bulkprocess";\r
+ }\r
+}\r