diff options
Diffstat (limited to 'vid-app-common/src/test/java/org/opencomp')
4 files changed, 0 insertions, 420 deletions
diff --git a/vid-app-common/src/test/java/org/opencomp/vid/controller/MsoControllerTest.java b/vid-app-common/src/test/java/org/opencomp/vid/controller/MsoControllerTest.java deleted file mode 100644 index 731668dc2..000000000 --- a/vid-app-common/src/test/java/org/opencomp/vid/controller/MsoControllerTest.java +++ /dev/null @@ -1,112 +0,0 @@ -package org.opencomp.vid.controller; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import org.apache.commons.lang.StringEscapeUtils; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.openecomp.portalsdk.core.util.SystemProperties; -import org.openecomp.vid.controller.MsoConfig; -import org.openecomp.vid.controller.MsoController; -import org.openecomp.vid.domain.mso.RequestInfo; -import org.openecomp.vid.factories.MsoRequestFactory; -import org.openecomp.vid.mso.rest.*; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; - -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.assertEquals; - -@RunWith(SpringJUnit4ClassRunner.class) -@WebAppConfiguration -@ContextConfiguration(classes = {SystemProperties.class , MsoConfig.class}) -public class MsoControllerTest { - - @Autowired - MsoRequestFactory msoRequestFactory; - - //@Test - public void testInstanceCreationNew() throws Exception { - - RequestDetails requestDetails = msoRequestFactory.createMsoRequest("msoRequest.json"); - MsoController msoController = new MsoController(); - ResponseEntity<String> responseEntityNew = msoController.createSvcInstanceNew(null, requestDetails); - ResponseEntity<String> responseEntity = msoController.createSvcInstance(null, requestDetails); - assertEquals(responseEntityNew, responseEntity); - - } - - //@Test - public void testInstanceCreationLocalWithRest() throws Exception { - - RequestDetails requestDetails = msoRequestFactory.createMsoRequest("msoRequest.json"); - MsoController msoController = new MsoController(); - ResponseEntity<String> responseEntityNew = msoController.createSvcInstance(null, requestDetails); - ResponseEntity<String> responseEntityRest = msoController.createSvcInstanceNewRest(null, requestDetails); - - assertEquals(responseEntityNew.getBody(), responseEntityRest.getBody()); - - } - - //@Test - public void testInstanceCreation() throws Exception { - - RequestDetails requestDetails = msoRequestFactory.createMsoRequest("msoRequest.json"); - MsoController msoController = new MsoController(); - ResponseEntity<String> responseEntity = msoController.createSvcInstance(null, requestDetails); - - - assertEquals(responseEntity.getBody(), "{ \"status\": 200, \"entity\": {\n" + - " \"requestReferences\": {\n" + - " \"instanceId\": \"ba00de9b-3c3e-4b0a-a1ad-0c5489e711fb\",\n" + - " \"requestId\": \"311cc766-b673-4a50-b9c5-471f68914586\"\n" + - " }\n" + - "}}"); - - } - - @Test - public void testGetOrchestrationRequestsForDashboard() throws Exception{ - MsoController msoController = new MsoController(); - List<Request> orchestrationRequestsForDashboard = msoController.getOrchestrationRequestsForDashboard(); - - assertEquals(orchestrationRequestsForDashboard.size() , 2); - } - - @Test - public void testGetManualTasksByRequestId() throws Exception{ - MsoController msoController = new MsoController(); - List<Task> orchestrationRequestsForDashboard = msoController.getManualTasksByRequestId("za1234d1-5a33-55df-13ab-12abad84e335"); - - assertEquals(orchestrationRequestsForDashboard.get(0).getTaskId() , "daf4dd84-b77a-42da-a051-3239b7a9392c"); - } - - - public void testCompleteManualTask() throws Exception{ // TODO not done yet - RequestInfo requestInfo = new RequestInfo(); - requestInfo.setResponseValue("rollback"); - requestInfo.setRequestorId("abc"); - requestInfo.setSource("VID"); - RequestDetails requestDetails = new RequestDetails(); - requestDetails.setRequestInfo(requestInfo); - MsoController msoController = new MsoController(); - ResponseEntity<String> responseEntity = msoController.manualTaskComplete("daf4dd84-b77a-42da-a051-3239b7a9392c" , requestDetails); - String assertString = "{ \\\"status\\\": 200, \\\"entity\\\": {\\n\" +\n" + - " \" \\\"taskRequestReference\\\": {\\n\" +\n" + - " \" \\\"taskId\\\": \\\"daf4dd84-b77a-42da-a051-3239b7a9392c\\\"\\n\" +\n" + - " \" }\\n\" +\n" + - " \"}\\n\" +\n" + - " \"}"; - assertEquals(responseEntity.getBody() , StringEscapeUtils.unescapeJava(assertString)); - } - - - - - -} diff --git a/vid-app-common/src/test/java/org/opencomp/vid/controller/ToscaParserMockHelper.java b/vid-app-common/src/test/java/org/opencomp/vid/controller/ToscaParserMockHelper.java deleted file mode 100644 index a9a902b6a..000000000 --- a/vid-app-common/src/test/java/org/opencomp/vid/controller/ToscaParserMockHelper.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.opencomp.vid.controller; - -import org.openecomp.vid.model.NewServiceModel; - -/** - * Created by moriya1 on 04/07/2017. - */ -public class ToscaParserMockHelper { - - private String uuid; - private String filePath; - private NewServiceModel newServiceModel; - - public ToscaParserMockHelper(String uuid, String filePath) { - this.uuid = uuid; - this.filePath = filePath; - } - - public String getUuid() { - return uuid; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - - public String getFilePath() { - return filePath; - } - - public void setFilePath(String filePath) { - this.filePath = filePath; - } - - public NewServiceModel getNewServiceModel() { - return newServiceModel; - } - - public void setNewServiceModel(NewServiceModel newServiceModel) { - this.newServiceModel = newServiceModel; - } -} diff --git a/vid-app-common/src/test/java/org/opencomp/vid/controller/VidControllerTest.java b/vid-app-common/src/test/java/org/opencomp/vid/controller/VidControllerTest.java deleted file mode 100644 index 8596cf3d4..000000000 --- a/vid-app-common/src/test/java/org/opencomp/vid/controller/VidControllerTest.java +++ /dev/null @@ -1,201 +0,0 @@ -package org.opencomp.vid.controller; - -import net.javacrumbs.jsonunit.JsonAssert; -import org.apache.commons.io.IOUtils; -import org.codehaus.jackson.map.ObjectMapper; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.openecomp.portalsdk.core.util.SystemProperties; -import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; -import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory; -import org.openecomp.sdc.tosca.parser.impl.SdcTypes; -import org.openecomp.vid.aai.AaiClient; -import org.openecomp.vid.aai.AaiResponse; -import org.openecomp.vid.asdc.AsdcCatalogException; -import org.openecomp.vid.asdc.AsdcClient; -import org.openecomp.vid.asdc.parser.ToscaParserImpl2; -import org.openecomp.vid.controller.WebConfig; -import org.openecomp.vid.model.*; -import org.openecomp.vid.properties.AsdcClientConfiguration; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Path; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import javax.servlet.ServletContext; - -import static org.opencomp.vid.testUtils.TestUtils.assertJsonStringEqualsIgnoreNulls; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {WebConfig.class, AsdcClientConfiguration.class,SystemProperties.class }) -@WebAppConfiguration - -public class VidControllerTest { - - @Autowired - private AsdcClient asdcClient; - - @Autowired - ServletContext context; - public class Constants{ - public static final String vfUuid = "48a52540-8772-4368-9cdb-1f124ea5c931"; - public static final String vlUuid = "68101369-6f08-4e99-9a28-fa6327d344f3"; - public static final String PNFUuid = "73e1322a-8a9a-49dc-9558-b0c5c5770e4a"; - public static final String vfFilePath = "vf-csar.JSON"; - public static final String vlFilePath = "vl-csar.JSON"; - public static final String PNFFilePath = "/vid_internal/vid-app-common/src/main/resources/pnf.csar"; - } - - private ToscaParserImpl2 p2 = new ToscaParserImpl2(); - private ObjectMapper om = new ObjectMapper(); - - - @Test - public void test() { - AaiClient client = new AaiClient(context); - AaiResponse<?> response = client.getVNFData(); - try { - System.out.println(new ObjectMapper().writeValueAsString(response)); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void checkPNFFieldsExist() throws SdcToscaParserException, AsdcCatalogException { - String serviceRoleString = "serviceRole"; - String serviceTypeString = "serviceType"; - - SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); - ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(getCsarPath(Constants.PNFUuid).toString()); - List<org.openecomp.sdc.toscaparser.api.NodeTemplate> pnfs = sdcCsarHelper.getServiceNodeTemplateBySdcType(SdcTypes.PNF); - Assert.assertEquals(sdcCsarHelper.getServiceMetadata().getValue(serviceTypeString).toLowerCase(),"transport"); - Assert.assertEquals(sdcCsarHelper.getServiceMetadata().getValue(serviceRoleString).toLowerCase(),"pnf"); - Assert.assertTrue(pnfs.size()>0); - - } - - - @Test - public void assertEqualsBetweenServices() throws Exception { - for (ToscaParserMockHelper mockHelper: getExpectedServiceModel()) { - Service expectedService = mockHelper.getNewServiceModel().getService(); - Service actualService = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getService(); - JsonAssert.assertJsonEquals(expectedService, actualService); - } - } - - //@Test - // bug in SDC tosca filterNodeTemplatePropertiesByValue - public void assertEqualBetweenObjects() throws Exception { - for (ToscaParserMockHelper mockHelper: getExpectedServiceModel()) { - ServiceModel actualServiceModel = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())); - JsonAssert.assertJsonEquals(mockHelper.getNewServiceModel(), actualServiceModel); - /*java.lang.AssertionError: JSON documents are different: - Different keys found in node "networks.ExtVL 0.commands". Expected [exVL_naming#naming_policy, network_role, network_scope], got [network_role, network_scope]. Missing: "networks.ExtVL 0.commands.exVL_naming#naming_policy" - Different keys found in node "networks.ExtVL 0.inputs". Expected [exVL_naming#naming_policy, network_role, network_scope], got [network_role, network_scope]. Missing: "networks.ExtVL 0.inputs.exVL_naming#naming_policy"*/ - } - } - - @Test - public void assertEqualsBetweenNetworkNodes() throws Exception { - for (ToscaParserMockHelper mockHelper: getExpectedServiceModel()) { - Map<String, Network> expectedNetworksMap = mockHelper.getNewServiceModel().getNetworks(); - Map<String, Network> actualNetworksMap = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getNetworks(); - for (Map.Entry<String, Network> entry : expectedNetworksMap.entrySet()) { - Network expectedNetwork = entry.getValue(); - Network actualNetwork = actualNetworksMap.get(entry.getKey()); - Assert.assertEquals(expectedNetwork.getModelCustomizationName(), actualNetwork.getModelCustomizationName()); - verifyBaseNodeProperties(expectedNetwork, actualNetwork); - compareProperties(expectedNetwork.getProperties(), actualNetwork.getProperties()); - } - } - } - - //Because we are not supporting the old flow, the JSON are different by definition. - @Test - public void assertEqualsBetweenVnfsOfTosca() throws Exception { - for (ToscaParserMockHelper mockHelper: getExpectedServiceModel()) { - Map<String, VNF> expectedVnfsMap = mockHelper.getNewServiceModel().getVnfs(); - Map<String, VNF> actualVnfsMap = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVnfs(); - for (Map.Entry<String, VNF> entry : expectedVnfsMap.entrySet()) { - VNF expectedVnf = entry.getValue(); - VNF actualVnf = actualVnfsMap.get(entry.getKey()); - verifyBaseNodeProperties(expectedVnf, actualVnf); - Assert.assertEquals(expectedVnf.getModelCustomizationName(), actualVnf.getModelCustomizationName()); - compareProperties(expectedVnf.getProperties(), actualVnf.getProperties()); - assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedVnf), om.writeValueAsString(actualVnf)); - } - } - } - - @Test - public void assertEqualsBetweenVolumeGroups() throws Exception { - for (ToscaParserMockHelper mockHelper: getExpectedServiceModel()) { - Path cSarPath = getCsarPath(mockHelper.getUuid()); - Map<String, VolumeGroup> actualVolumeGroups = new HashMap<>(); - if(cSarPath != null) { - actualVolumeGroups = p2.makeServiceModel(cSarPath, getServiceByUuid(mockHelper.getUuid())).getVolumeGroups(); - } - Map<String, VolumeGroup> expectedVolumeGroups = mockHelper.getNewServiceModel().getVolumeGroups(); - JsonAssert.assertJsonEquals(actualVolumeGroups, expectedVolumeGroups); - } - } - - @Test - public void assertEqualsBetweenVfModules() throws Exception { - for (ToscaParserMockHelper mockHelper: getExpectedServiceModel()) { - Map<String, VfModule> actualVfModules = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVfModules(); - Map<String, VfModule> expectedVfModules = mockHelper.getNewServiceModel().getVfModules(); - JsonAssert.assertJsonEquals(actualVfModules, expectedVfModules); - } - } - - private void verifyBaseNodeProperties(Node expectedNode, Node actualNode) { - Assert.assertEquals(expectedNode.getName(), actualNode.getName()); - Assert.assertEquals(expectedNode.getCustomizationUuid(), actualNode.getCustomizationUuid()); - Assert.assertEquals(expectedNode.getDescription(), actualNode.getDescription()); - Assert.assertEquals(expectedNode.getInvariantUuid(), actualNode.getInvariantUuid()); - Assert.assertEquals(expectedNode.getUuid(), actualNode.getUuid()); - Assert.assertEquals(expectedNode.getVersion(), actualNode.getVersion()); - } - - private void compareProperties(Map<String, String> expectedProperties, Map<String, String> actualProperties) { - for (Map.Entry<String, String> property : expectedProperties.entrySet()) { - String expectedValue = property.getValue(); - String key = property.getKey(); - String actualValue = actualProperties.get(key); - Assert.assertEquals(expectedValue, actualValue); - } - } - - private ToscaParserMockHelper[] getExpectedServiceModel() throws IOException { - ToscaParserMockHelper[] mockHelpers = {new ToscaParserMockHelper(Constants.vlUuid, Constants.vlFilePath), new ToscaParserMockHelper(Constants.vfUuid, Constants.vfFilePath)}; - for(ToscaParserMockHelper mockHelper: mockHelpers) { - InputStream jsonFile = VidControllerTest.class.getClassLoader().getResourceAsStream(mockHelper.getFilePath()); - String expectedJsonAsString = IOUtils.toString(jsonFile).toString(); - NewServiceModel newServiceModel1 = om.readValue(expectedJsonAsString, NewServiceModel.class); - mockHelper.setNewServiceModel(newServiceModel1); - } - return mockHelpers; - } - - private Path getCsarPath(String uuid) throws AsdcCatalogException { - return asdcClient.getServiceToscaModel(UUID.fromString(uuid)); - } - - private org.openecomp.vid.asdc.beans.Service getServiceByUuid(String uuid) throws AsdcCatalogException { - return asdcClient.getService(UUID.fromString(uuid)); - } -}
\ No newline at end of file diff --git a/vid-app-common/src/test/java/org/opencomp/vid/testUtils/TestUtils.java b/vid-app-common/src/test/java/org/opencomp/vid/testUtils/TestUtils.java deleted file mode 100644 index 29115e0aa..000000000 --- a/vid-app-common/src/test/java/org/opencomp/vid/testUtils/TestUtils.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.opencomp.vid.testUtils; - -import org.json.JSONArray; -import org.json.JSONObject; -import org.junit.Assert; - -import java.util.Iterator; - -import static fj.parser.Parser.fail; - -/** - * Created by Oren on 6/7/17. - */ -public class TestUtils { - - /** - * The method compares between two jsons. the function assert that the actual object does not reduce or change the functionallity/parsing of the expected json. - * This means that if the expected JSON has a key which is null or the JSON doesn't have a key which contained in the expected JSON the assert will succeed and the will pass. - * For example : For JSON expected = {a:null} and actual {a:3} the test will pass - * Other example : For JSON expected = {a:3} and actual {a:null} the test will fail - * - * @param expected JSON - * @param actual JSON - */ - public static void assertJsonStringEqualsIgnoreNulls(String expected, String actual) { - if (expected == null || expected == JSONObject.NULL) {return;} - - JSONObject expectedJSON = new JSONObject(expected); - JSONObject actualJSON = new JSONObject(actual); - Iterator<?> keys = expectedJSON.keys(); - - while( keys.hasNext() ) { - String key = (String)keys.next(); - Object expectedValue = expectedJSON.get(key); - if (expectedValue == JSONObject.NULL){ - continue; - } - - Object actualValue = actualJSON.get(key); - - if (expectedValue instanceof JSONObject) { - String expectedVal = expectedValue.toString(); - String actualVal = actualValue.toString(); - assertJsonStringEqualsIgnoreNulls(expectedVal, actualVal); - } - else if (expectedValue instanceof JSONArray) { - if (actualValue instanceof JSONArray) { - JSONArray expectedJSONArray = (JSONArray)expectedValue; - JSONArray actualJSONArray = (JSONArray)expectedValue; - for (int i = 0; i < expectedJSONArray.length(); i++) { - String expectedItem = expectedJSONArray.getJSONObject(i).toString(); - String actualItem = actualJSONArray.getJSONObject(i).toString(); - assertJsonStringEqualsIgnoreNulls(expectedItem, actualItem); - } - } - else { - fail("expected: " + expectedValue + " got:" + actualValue); - } - } - else { - Assert.assertEquals(expectedValue, actualValue); - } - } - } -} |