diff options
Diffstat (limited to 'src/test/java')
9 files changed, 33 insertions, 1044 deletions
diff --git a/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java index 97b33e136..65ab4c5e1 100644 --- a/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java @@ -24,14 +24,11 @@ package org.onap.clamp.clds.it; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import javax.ws.rs.NotFoundException; @@ -42,7 +39,6 @@ import org.junit.runner.RunWith; import org.onap.clamp.clds.dao.CldsDao; import org.onap.clamp.clds.model.CldsEvent; import org.onap.clamp.clds.model.CldsModel; -import org.onap.clamp.clds.model.CldsMonitoringDetails; import org.onap.clamp.clds.model.CldsTemplate; import org.onap.clamp.clds.util.ResourceFileUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -67,8 +63,7 @@ public class CldsDaoItCase { /** * Setup the variable before the tests execution. * - * @throws IOException - * In case of issues when opening the files + * @throws IOException In case of issues when opening the files */ @Before public void setupBefore() throws IOException { @@ -144,17 +139,7 @@ public class CldsDaoItCase { newModel.setTemplateId(newTemplate.getId()); newModel.setDocText(newTemplate.getPropText()); CldsEvent.insEvent(cldsDao, newModel, "user", CldsEvent.ACTION_RESTART, CldsEvent.ACTION_STATE_COMPLETED, - "process-instance-id"); - } - - @Test - public void testGetCldsMonitoringDetails() { - List<CldsMonitoringDetails> cldsMonitoringDetailsList = new ArrayList<CldsMonitoringDetails>(); - cldsMonitoringDetailsList = cldsDao.getCldsMonitoringDetails(); - cldsMonitoringDetailsList.forEach(clName -> { - logger.info(clName.getCloseloopName()); - assertNotNull(clName.getCloseloopName()); - }); + "process-instance-id"); } } diff --git a/src/test/java/org/onap/clamp/clds/it/CldsDictionaryServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsDictionaryServiceItCase.java deleted file mode 100644 index 5218c9255..000000000 --- a/src/test/java/org/onap/clamp/clds/it/CldsDictionaryServiceItCase.java +++ /dev/null @@ -1,177 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * 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.clamp.clds.it; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -import java.util.LinkedList; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.mockito.Mockito; -import org.onap.clamp.clds.model.CldsDictionary; -import org.onap.clamp.clds.model.CldsDictionaryItem; -import org.onap.clamp.clds.service.CldsDictionaryService; -import org.onap.clamp.clds.util.LoggingUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.http.ResponseEntity; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.context.SecurityContext; -import org.springframework.security.core.userdetails.User; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * Test CLDS Dictionary Service APIs. - */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -public class CldsDictionaryServiceItCase { - - private static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsDictionaryServiceItCase.class); - @Autowired - private CldsDictionaryService cldsDictionaryService; - private CldsDictionary cldsDictionary; - private CldsDictionaryItem cldsDictionaryItem; - private List<GrantedAuthority> authList = new LinkedList<>(); - - private static final String DICTIONARY_NAME = "TestDictionary"; - - /** - * Setup the variable before the tests execution. - * - */ - @Before - public void setupBefore() { - authList.add(new SimpleGrantedAuthority("permission-type-cl|dev|read")); - authList.add(new SimpleGrantedAuthority("permission-type-cl|dev|update")); - authList.add(new SimpleGrantedAuthority("permission-type-template|dev|read")); - authList.add(new SimpleGrantedAuthority("permission-type-template|dev|update")); - authList.add(new SimpleGrantedAuthority("permission-type-filter-vf|dev|*")); - authList.add(new SimpleGrantedAuthority("permission-type-tosca|dev|read")); - authList.add(new SimpleGrantedAuthority("permission-type-tosca|dev|update")); - - Authentication authentication = - new UsernamePasswordAuthenticationToken(new User("admin", "", authList), "", authList); - SecurityContext securityContext = Mockito.mock(SecurityContext.class); - Mockito.when(securityContext.getAuthentication()).thenReturn(authentication); - - LoggingUtils util = Mockito.mock(LoggingUtils.class); - Mockito.doNothing().when(util).entering(Matchers.any(HttpServletRequest.class), Matchers.any(String.class)); - cldsDictionaryService.setLoggingUtil(util); - - cldsDictionaryService.setSecurityContext(securityContext); - - cldsDictionary = cldsDictionaryService.createDictionary(DICTIONARY_NAME); - - cldsDictionaryItem = new CldsDictionaryItem(); - cldsDictionaryItem.setDictElementShortName("TestDictionaryItemShortName"); - cldsDictionaryItem.setDictElementName("TestDictionaryItemName"); - cldsDictionaryItem.setDictElementType("string"); - cldsDictionaryItem.setDictionaryId(cldsDictionary.getDictionaryId()); - cldsDictionaryItem.setDictElementDesc("TestDictionaryItemDesc"); - cldsDictionaryService.createOrUpdateDictionaryElements(DICTIONARY_NAME, cldsDictionaryItem); - - logger.info("Initial Clds Dictionary uploaded in DB:" + cldsDictionaryItem); - } - - @Test - public void testCreateDictionaryFromString() { - String dictionaryName = "TestDefaultDictionary"; - CldsDictionary dictionary = cldsDictionaryService.createDictionary(dictionaryName); - assertNotNull(dictionary); - logger.info("CLDS Default Dictionary is:" + dictionary); - assertEquals(dictionaryName, dictionary.getDictionaryName()); - } - - @Test - public void testCreateOrUpdateDictionaryUsedByFrontend() { - ResponseEntity<CldsDictionary> responseEntity = - cldsDictionaryService.createOrUpdateDictionary(DICTIONARY_NAME, null); - CldsDictionary dictionary1 = responseEntity.getBody(); - - responseEntity = cldsDictionaryService.createOrUpdateDictionary(DICTIONARY_NAME, cldsDictionary); - CldsDictionary dictionary2 = responseEntity.getBody(); - - responseEntity = cldsDictionaryService.createOrUpdateDictionary(DICTIONARY_NAME, new CldsDictionary()); - CldsDictionary dictionary3 = responseEntity.getBody(); - - assertNotNull(dictionary1); - assertNotNull(dictionary2); - assertNotNull(dictionary3); - assertEquals(DICTIONARY_NAME, dictionary1.getDictionaryName()); - assertEquals(DICTIONARY_NAME, dictionary2.getDictionaryName()); - assertNotNull(dictionary3.getDictionaryName()); - assertEquals(DICTIONARY_NAME, dictionary3.getDictionaryName()); - } - - @Test - public void testCreateOrUpdateDictionaryElements() { - cldsDictionaryItem = new CldsDictionaryItem(); - cldsDictionaryItem.setDictElementShortName("TestDictionaryItemShortName1"); - cldsDictionaryItem.setDictElementName("TestDictionaryItemName1"); - cldsDictionaryItem.setDictElementType("string"); - cldsDictionaryItem.setDictionaryId(cldsDictionary.getDictionaryId()); - cldsDictionaryItem.setDictElementDesc("TestDictionaryItemDesc1"); - - ResponseEntity<CldsDictionaryItem> responseEntity = cldsDictionaryService - .createOrUpdateDictionaryElements(DICTIONARY_NAME, cldsDictionaryItem); - CldsDictionaryItem dictionaryItem = responseEntity.getBody(); - assertNotNull(dictionaryItem); - logger.info("CLDS Dictionary Item is:" + dictionaryItem); - assertEquals("TestDictionaryItemName1", dictionaryItem.getDictElementName()); - } - - @Test - public void testGetAllDictionaryNames() { - ResponseEntity<List<CldsDictionary>> responseEntity = cldsDictionaryService.getAllDictionaryNames(); - List<CldsDictionary> dictionaries = responseEntity.getBody(); - assertNotNull(dictionaries); - logger.info("CLDS Dictionary List is:" + dictionaries); - } - - @Test - public void testGetDictionaryElementsByName() { - ResponseEntity<List<CldsDictionaryItem>> responseEntity = cldsDictionaryService - .getDictionaryElementsByName(DICTIONARY_NAME); - List<CldsDictionaryItem> dictionaryItems = responseEntity.getBody(); - assertNotNull(dictionaryItems); - logger.info("CLDS Dictionary Item LIst is:" + dictionaryItems); - } -}
\ No newline at end of file diff --git a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java index faeb04182..963f45bec 100644 --- a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java @@ -35,32 +35,20 @@ import java.util.List; import java.util.Properties; import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.NotFoundException; -import javax.xml.transform.TransformerException; -import org.apache.commons.lang3.RandomStringUtils; -import org.json.simple.parser.ParseException; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Matchers; import org.mockito.Mockito; import org.onap.clamp.clds.dao.CldsDao; -import org.onap.clamp.clds.model.CldsEvent; import org.onap.clamp.clds.model.CldsInfo; -import org.onap.clamp.clds.model.CldsModel; -import org.onap.clamp.clds.model.CldsMonitoringDetails; -import org.onap.clamp.clds.model.CldsTemplate; -import org.onap.clamp.clds.model.DcaeEvent; import org.onap.clamp.clds.service.CldsService; import org.onap.clamp.clds.util.LoggingUtils; import org.onap.clamp.clds.util.ResourceFileUtil; -import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; @@ -93,8 +81,7 @@ public class CldsServiceItCase { /** * Setup the variable before the tests execution. * - * @throws IOException - * In case of issues when opening the files + * @throws IOException In case of issues when opening the files */ @Before public void setupBefore() throws IOException { @@ -154,127 +141,4 @@ public class CldsServiceItCase { assertEquals(cldsInfo.getCldsVersion(), prop.getProperty("clds.version")); assertEquals(cldsInfo.getUserName(), "admin"); } - - @Test - public void testGetCldsDetails() throws IOException { - List<CldsMonitoringDetails> cldsMonitoringDetailsList = cldsService.getCldsDetails(); - assertNotNull(cldsMonitoringDetailsList); - } - - @Test(expected = NotFoundException.class) - public void testCompleteFlow() throws TransformerException, ParseException { - SecurityContext securityContext = Mockito.mock(SecurityContext.class); - Mockito.when(securityContext.getAuthentication()).thenReturn(authentication); - - cldsService.setSecurityContext(securityContext); - // Add the template first - CldsTemplate newTemplate = new CldsTemplate(); - String randomNameTemplate = RandomStringUtils.randomAlphanumeric(5); - newTemplate.setName(randomNameTemplate); - newTemplate.setBpmnText(bpmnText); - newTemplate.setImageText(imageText); - // Save the template in DB - cldsDao.setTemplate(newTemplate, "user"); - // Test if it's well there - CldsTemplate newTemplateRead = cldsDao.getTemplate(randomNameTemplate); - assertEquals(bpmnText, newTemplateRead.getBpmnText()); - assertEquals(imageText, newTemplateRead.getImageText()); - // Save the model - String randomNameModel = RandomStringUtils.randomAlphanumeric(5); - CldsModel newModel = new CldsModel(); - newModel.setName(randomNameModel); - newModel.setBpmnText(bpmnText); - newModel.setImageText(imageText); - newModel.setPropText(bpmnPropText); - newModel.setControlNamePrefix("ClosedLoop-"); - newModel.setTemplateName(randomNameTemplate); - newModel.setTemplateId(newTemplate.getId()); - newModel.setDocText(docText); - // Test the PutModel method - - cldsService.putModel(randomNameModel, newModel); - - assertEquals(bpmnText, cldsService.getBpmnXml(randomNameModel)); - assertEquals(imageText, cldsService.getImageXml(randomNameModel)); - - // Verify whether it has been added properly or not - assertNotNull(cldsDao.getModel(randomNameModel)); - - CldsModel model = cldsService.getModel(randomNameModel); - // Verify with GetModel - assertEquals(model.getTemplateName(), randomNameTemplate); - assertEquals(model.getName(), randomNameModel); - - assertTrue(cldsService.getModelNames().size() >= 1); - - // Should fail - ResponseEntity<?> responseEntity = cldsService.putModelAndProcessAction(CldsEvent.ACTION_SUBMIT, - randomNameModel, "false", cldsService.getModel(randomNameModel)); - assertTrue(responseEntity.getStatusCode().equals(HttpStatus.OK)); - assertNotNull(responseEntity.getBody()); - assertTrue(CldsModel.STATUS_DISTRIBUTED.equals(((CldsModel) responseEntity.getBody()).getStatus())); - assertTrue(CldsModel.STATUS_DISTRIBUTED.equals(cldsService.getModel(randomNameModel).getStatus())); - - responseEntity = cldsService.deployModel(randomNameModel, cldsService.getModel(randomNameModel)); - assertNotNull(responseEntity); - assertTrue(responseEntity.getStatusCode().equals(HttpStatus.OK)); - assertNotNull(responseEntity.getBody()); - assertTrue(CldsModel.STATUS_ACTIVE.equals(((CldsModel) responseEntity.getBody()).getStatus())); - assertTrue(CldsModel.STATUS_ACTIVE.equals(cldsService.getModel(randomNameModel).getStatus())); - - responseEntity = cldsService.putModelAndProcessAction(CldsEvent.ACTION_STOP, randomNameModel, "false", - cldsService.getModel(randomNameModel)); - assertTrue(responseEntity.getStatusCode().equals(HttpStatus.OK)); - assertNotNull(responseEntity.getBody()); - assertTrue(CldsModel.STATUS_STOPPED.equals(((CldsModel) responseEntity.getBody()).getStatus())); - assertTrue(CldsModel.STATUS_STOPPED.equals(cldsService.getModel(randomNameModel).getStatus())); - - responseEntity = cldsService.putModelAndProcessAction(CldsEvent.ACTION_RESTART, randomNameModel, "false", - cldsService.getModel(randomNameModel)); - assertTrue(responseEntity.getStatusCode().equals(HttpStatus.OK)); - assertNotNull(responseEntity.getBody()); - assertTrue(CldsModel.STATUS_ACTIVE.equals(((CldsModel) responseEntity.getBody()).getStatus())); - assertTrue(CldsModel.STATUS_ACTIVE.equals(cldsService.getModel(randomNameModel).getStatus())); - - responseEntity = cldsService.putModelAndProcessAction(CldsEvent.ACTION_UPDATE, randomNameModel, "false", - cldsService.getModel(randomNameModel)); - assertTrue(responseEntity.getStatusCode().equals(HttpStatus.OK)); - assertNotNull(responseEntity.getBody()); - assertTrue(CldsModel.STATUS_ACTIVE.equals(((CldsModel) responseEntity.getBody()).getStatus())); - assertTrue(CldsModel.STATUS_ACTIVE.equals(cldsService.getModel(randomNameModel).getStatus())); - - responseEntity = cldsService.unDeployModel(randomNameModel, cldsService.getModel(randomNameModel)); - assertNotNull(responseEntity); - assertTrue(responseEntity.getStatusCode().equals(HttpStatus.OK)); - assertNotNull(responseEntity.getBody()); - assertTrue(CldsModel.STATUS_DISTRIBUTED.equals(((CldsModel) responseEntity.getBody()).getStatus())); - assertTrue(CldsModel.STATUS_DISTRIBUTED.equals(cldsService.getModel(randomNameModel).getStatus())); - - responseEntity = cldsService.putModelAndProcessAction(CldsEvent.ACTION_DELETE, randomNameModel, "false", - cldsService.getModel(randomNameModel)); - assertNotNull(responseEntity); - assertTrue(responseEntity.getStatusCode().equals(HttpStatus.OK)); - assertNotNull(responseEntity.getBody()); - // This will raise an exception - cldsService.getModel(randomNameModel); - } - - @Test - public void testDcaePost() { - DcaeEvent dcaeEvent = new DcaeEvent(); - dcaeEvent.setArtifactName("ClosedLoop_with-enough-characters_TestArtifact.yml"); - dcaeEvent.setEvent(DcaeEvent.EVENT_CREATED); - dcaeEvent.setResourceUUID("1"); - dcaeEvent.setServiceUUID("2"); - assertEquals(cldsService.postDcaeEvent("false", dcaeEvent), - "event=created serviceUUID=2 resourceUUID=1 artifactName=" - + "ClosedLoop_with-enough-characters_TestArtifact.yml instance count=0 isTest=false"); - } - - @Test - public void testGetSdcProperties() throws IOException { - JSONAssert.assertEquals( - ResourceFileUtil.getResourceAsString("example/sdc/expected-result/sdc-properties-global.json"), - cldsService.getSdcProperties(), true); - } } diff --git a/src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java deleted file mode 100644 index ba8b0b79d..000000000 --- a/src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java +++ /dev/null @@ -1,171 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017-2018 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.clamp.clds.it; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -import java.io.IOException; -import java.security.Principal; -import java.util.LinkedList; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.mockito.Mockito; -import org.onap.clamp.clds.dao.CldsDao; -import org.onap.clamp.clds.model.CldsTemplate; -import org.onap.clamp.clds.model.ValueItem; -import org.onap.clamp.clds.service.CldsTemplateService; -import org.onap.clamp.clds.util.LoggingUtils; -import org.onap.clamp.clds.util.ResourceFileUtil; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.context.SecurityContext; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.core.userdetails.User; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * Test HTTP and HTTPS settings + redirection of HTTP to HTTPS. - */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -public class CldsTemplateServiceItCase { - - protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsTemplateServiceItCase.class); - @Autowired - private CldsTemplateService cldsTemplateService; - @Autowired - private CldsDao cldsDao; - private String bpmnText; - private String imageText; - private String bpmnPropText; - private CldsTemplate cldsTemplate; - private Authentication authentication; - private List<GrantedAuthority> authList = new LinkedList<GrantedAuthority>(); - private LoggingUtils util; - - /** - * Setup the variable before the tests execution. - * - * @throws IOException - * In case of issues when opening the files - */ - @Before - public void setupBefore() throws IOException { - authList.add(new SimpleGrantedAuthority("permission-type-cl|dev|read")); - authList.add(new SimpleGrantedAuthority("permission-type-cl|dev|update")); - authList.add(new SimpleGrantedAuthority("permission-type-template|dev|read")); - authList.add(new SimpleGrantedAuthority("permission-type-template|dev|update")); - authList.add(new SimpleGrantedAuthority("permission-type-filter-vf|dev|*")); - authentication = new UsernamePasswordAuthenticationToken(new User("admin", "", authList), "", authList); - - SecurityContext securityContext = Mockito.mock(SecurityContext.class); - Mockito.when(securityContext.getAuthentication()).thenReturn(authentication); - - util = Mockito.mock(LoggingUtils.class); - Mockito.doNothing().when(util).entering(Matchers.any(HttpServletRequest.class), Matchers.any(String.class)); - cldsTemplateService.setLoggingUtil(util); - - cldsTemplateService.setSecurityContext(securityContext); - bpmnText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-template.xml"); - imageText = ResourceFileUtil.getResourceAsString("example/dao/image-template.xml"); - bpmnPropText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-prop.json"); - cldsTemplate = new CldsTemplate(); - cldsTemplate.setName("testModel"); - cldsTemplate.setBpmnText(bpmnText); - cldsTemplate.setImageText(imageText); - cldsTemplate.setPropText(bpmnPropText); - cldsTemplateService.putTemplate("testModel", cldsTemplate); - } - - @Test - public void testPutTemplate() throws Exception { - CldsTemplate savedTemplate = CldsTemplate.retrieve(cldsDao, "testModel", false); - assertNotNull(savedTemplate); - logger.info("saved template bpmn text is:" + savedTemplate.getBpmnText()); - assertEquals(bpmnText, savedTemplate.getBpmnText()); - assertEquals(imageText, savedTemplate.getImageText()); - assertEquals(bpmnPropText, savedTemplate.getPropText()); - assertEquals("testModel", savedTemplate.getName()); - } - - @Test - public void testGetTemplate() throws Exception { - CldsTemplate getTemplate = cldsTemplateService.getTemplate("testModel"); - assertNotNull(getTemplate); - assertEquals(bpmnText, getTemplate.getBpmnText()); - assertEquals(imageText, getTemplate.getImageText()); - assertEquals(bpmnPropText, getTemplate.getPropText()); - assertEquals("testModel", getTemplate.getName()); - } - - @Test - public void testGetImageXml() throws Exception { - String imageXml = cldsTemplateService.getImageXml("testModel"); - assertEquals(imageText, imageXml); - } - - @Test - public void testGetBpmnTemplate() throws Exception { - String bpmnTemplate = cldsTemplateService.getBpmnTemplate("testModel"); - assertEquals(bpmnText, bpmnTemplate); - } - - @Test - public void testGetTemplateNames() throws Exception { - CldsTemplate cldsTemplateNew = new CldsTemplate(); - cldsTemplateNew.setName("testModelNew"); - cldsTemplateNew.setBpmnText(bpmnText); - cldsTemplateNew.setImageText(imageText); - cldsTemplateNew.setPropText(bpmnPropText); - cldsTemplateService.putTemplate("testModelNew", cldsTemplateNew); - List<ValueItem> templateNames = cldsTemplateService.getTemplateNames(); - boolean testModel = false; - boolean testModelNew = false; - for (ValueItem item : templateNames) { - if (item.getValue().equals("testModel")) { - testModel = true; - } - if (item.getValue().equals("testModelNew")) { - testModelNew = true; - } - } - assertTrue(testModel || testModelNew); - } -} diff --git a/src/test/java/org/onap/clamp/clds/it/CldsToscaServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsToscaServiceItCase.java deleted file mode 100644 index 992c06e8c..000000000 --- a/src/test/java/org/onap/clamp/clds/it/CldsToscaServiceItCase.java +++ /dev/null @@ -1,136 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2018 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.clamp.clds.it; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -import java.io.IOException; -import java.util.LinkedList; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.mockito.Mockito; -import org.onap.clamp.clds.model.CldsToscaModel; -import org.onap.clamp.clds.service.CldsToscaService; -import org.onap.clamp.clds.util.LoggingUtils; -import org.onap.clamp.clds.util.ResourceFileUtil; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.http.ResponseEntity; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.context.SecurityContext; -import org.springframework.security.core.userdetails.User; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * Test CLDS Tosca Service APIs. - */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -public class CldsToscaServiceItCase { - - protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsToscaServiceItCase.class); - @Autowired - private CldsToscaService cldsToscaService; - private String toscaModelYaml; - private Authentication authentication; - private CldsToscaModel cldsToscaModel; - private List<GrantedAuthority> authList = new LinkedList<>(); - private LoggingUtils util; - - /** - * Setup the variable before the tests execution. - * - * @throws IOException - * In case of issues when opening the files - */ - @Before - public void setupBefore() throws IOException { - authList.add(new SimpleGrantedAuthority("permission-type-cl|dev|read")); - authList.add(new SimpleGrantedAuthority("permission-type-cl|dev|update")); - authList.add(new SimpleGrantedAuthority("permission-type-template|dev|read")); - authList.add(new SimpleGrantedAuthority("permission-type-template|dev|update")); - authList.add(new SimpleGrantedAuthority("permission-type-filter-vf|dev|*")); - authList.add(new SimpleGrantedAuthority("permission-type-tosca|dev|read")); - authList.add(new SimpleGrantedAuthority("permission-type-tosca|dev|update")); - authentication = new UsernamePasswordAuthenticationToken(new User("admin", "", authList), "", authList); - - SecurityContext securityContext = Mockito.mock(SecurityContext.class); - Mockito.when(securityContext.getAuthentication()).thenReturn(authentication); - - util = Mockito.mock(LoggingUtils.class); - Mockito.doNothing().when(util).entering(Matchers.any(HttpServletRequest.class), Matchers.any(String.class)); - cldsToscaService.setLoggingUtil(util); - - cldsToscaService.setSecurityContext(securityContext); - - toscaModelYaml = ResourceFileUtil.getResourceAsString("tosca/tca-policy-test.yaml"); - - cldsToscaModel = new CldsToscaModel(); - cldsToscaModel.setToscaModelName("tca-policy-test"); - cldsToscaModel.setToscaModelYaml(toscaModelYaml); - cldsToscaModel.setUserId("admin"); - cldsToscaModel.setPolicyType("tca"); - cldsToscaService.parseToscaModelAndSave("tca-policy-test", cldsToscaModel); - logger.info("Initial Tosca Model uploaded in DB:" + cldsToscaModel); - } - - @Test - public void testParseToscaModelAndSave() throws Exception { - ResponseEntity responseEntity = cldsToscaService.parseToscaModelAndSave("tca-policy-test", cldsToscaModel); - CldsToscaModel savedModel = (CldsToscaModel) responseEntity.getBody(); - assertNotNull(savedModel); - logger.info("Parsed Tosca Model is:" + savedModel); - assertEquals("tca-policy-test", savedModel.getToscaModelName()); - } - - @Test - public void testGetToscaModel() throws Exception { - CldsToscaModel savedModel = cldsToscaService.getToscaModel("tca-policy-test"); - assertNotNull(savedModel); - assertEquals("tca-policy-test", savedModel.getToscaModelName()); - } - - @Test - public void testGetToscaModelsByPolicyType() throws Exception { - CldsToscaModel savedModel = cldsToscaService.getToscaModelsByPolicyType("tca"); - assertNotNull(savedModel); - assertEquals("tca-policy-test", savedModel.getToscaModelName()); - assertEquals("tca", savedModel.getPolicyType()); - } - -} diff --git a/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java b/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java index 9b83e7216..7c520a252 100644 --- a/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java @@ -45,7 +45,7 @@ import org.springframework.test.util.ReflectionTestUtils; */ @RunWith(SpringRunner.class) @SpringBootTest -@ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller") +@ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller-new") public class SdcControllersConfigurationItCase { @Autowired @@ -60,7 +60,7 @@ public class SdcControllersConfigurationItCase { public void testGetAllDefinedControllers() throws IOException { loadFile("classpath:/clds/sdc-controllers-config.json"); Map<String, SdcSingleControllerConfiguration> mapResult = sdcControllersConfiguration - .getAllDefinedControllers(); + .getAllDefinedControllers(); assertTrue(mapResult.size() == 2); assertEquals("sdc-controller1", mapResult.get("sdc-controller1").getSdcControllerName()); assertEquals("sdc-controller2", mapResult.get("sdc-controller2").getSdcControllerName()); @@ -69,10 +69,10 @@ public class SdcControllersConfigurationItCase { @Test public void testGetSdcSingleControllerConfiguration() throws IOException { loadFile("classpath:/clds/sdc-controllers-config.json"); - assertEquals("sdc-controller1", - sdcControllersConfiguration.getSdcSingleControllerConfiguration("sdc-controller1").getSdcControllerName()); - assertEquals("sdc-controller2", - sdcControllersConfiguration.getSdcSingleControllerConfiguration("sdc-controller2").getSdcControllerName()); + assertEquals("sdc-controller1", sdcControllersConfiguration + .getSdcSingleControllerConfiguration("sdc-controller1").getSdcControllerName()); + assertEquals("sdc-controller2", sdcControllersConfiguration + .getSdcSingleControllerConfiguration("sdc-controller2").getSdcControllerName()); } @Test(expected = JsonSyntaxException.class) diff --git a/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java b/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java index 0f0ecaedc..695b85166 100644 --- a/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java @@ -27,11 +27,13 @@ package org.onap.clamp.clds.it.sdc.controller; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; + import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; + import org.assertj.core.api.Assertions; import org.junit.Before; import org.junit.Test; @@ -104,45 +106,48 @@ public class SdcSingleControllerItCase { */ @Before public void init() { - sdcSingleController = new SdcSingleController(clampProp, csarInstaller, - SdcSingleControllerConfigurationTest.loadControllerConfiguration("clds/sdc-controller-config-TLS.json", - "sdc-controller1"), - null) { + sdcSingleController = new SdcSingleController(clampProp, csarInstaller, SdcSingleControllerConfigurationTest + .loadControllerConfiguration("clds/sdc-controller-config-TLS.json", "sdc-controller1"), null) { }; } @Test public void testTreatNotification() { - //when + // when sdcSingleController.treatNotification(buildFakeSdcNotification()); - //then + // then Assertions.assertThat(sdcSingleController.getNbOfNotificationsOngoing()).isEqualTo(0); } @Test public void testCloseSdc() throws SdcControllerException { - //when + // when sdcSingleController.closeSdc(); - //then + // then assertThat(sdcSingleController.getControllerStatus()).isEqualTo(SdcSingleControllerStatus.STOPPED); } @Test - public void testActivateCallback() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException, ClassNotFoundException { - //given - MDCAdapter mdcAdapter = MDC.getMDCAdapter(); - Class<?> innerClass = Class.forName("org.onap.clamp.clds.sdc.controller.SdcSingleController$SdcNotificationCallBack"); - Constructor<?> constructor = innerClass.getDeclaredConstructor(SdcSingleController.class, SdcSingleController.class); + public void testActivateCallback() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, + InstantiationException, ClassNotFoundException { + // given + + Class<?> innerClass = Class + .forName("org.onap.clamp.clds.sdc.controller.SdcSingleController$SdcNotificationCallBack"); + Constructor<?> constructor = innerClass.getDeclaredConstructor(SdcSingleController.class, + SdcSingleController.class); constructor.setAccessible(true); - Object child = constructor.newInstance(sdcSingleController,sdcSingleController); - Method method = child.getClass().getDeclaredMethod("activateCallback",INotificationData.class); + Object child = constructor.newInstance(sdcSingleController, sdcSingleController); + Method method = child.getClass().getDeclaredMethod("activateCallback", INotificationData.class); method.setAccessible(true); - //when - method.invoke(child,buildFakeSdcNotification()); - //then + MDCAdapter mdcAdapter = MDC.getMDCAdapter(); + // when + method.invoke(child, buildFakeSdcNotification()); + // then assertThat(mdcAdapter.get("ResponseCode")).isEqualTo("0"); assertThat(mdcAdapter.get("StatusCode")).isEqualTo("COMPLETE"); - assertThat(mdcAdapter.get("ResponseDescription")).isEqualTo("SDC Notification received and processed successfully"); + assertThat(mdcAdapter.get("ResponseDescription")) + .isEqualTo("SDC Notification received and processed successfully"); assertThat(mdcAdapter.get("ClassName")).isEqualTo(child.getClass().getName()); } } diff --git a/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java deleted file mode 100644 index e1b963cc4..000000000 --- a/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java +++ /dev/null @@ -1,214 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Modifications copyright (c) 2019 Nokia - * =================================================================== - * 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.clamp.clds.it.sdc.controller.installer; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.RandomStringUtils; -import org.json.JSONException; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.onap.clamp.clds.dao.CldsDao; -import org.onap.clamp.clds.exception.policy.PolicyModelException; -import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException; -import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException; -import org.onap.clamp.clds.model.CldsModel; -import org.onap.clamp.clds.model.CldsTemplate; -import org.onap.clamp.clds.sdc.controller.installer.BlueprintArtifact; -import org.onap.clamp.clds.sdc.controller.installer.CsarHandler; -import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller; -import org.onap.clamp.clds.sdc.controller.installer.CsarInstallerImpl; -import org.onap.clamp.clds.util.ResourceFileUtil; -import org.onap.sdc.api.notification.INotificationData; -import org.onap.sdc.api.notification.IResourceInstance; -import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.onap.sdc.toscaparser.api.elements.Metadata; -import org.skyscreamer.jsonassert.JSONAssert; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -@ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller") -public class CsarInstallerItCase { - - private static final String INVARIANT_SERVICE_UUID = "4cc5b45a-1f63-4194-8100-cd8e14248c92"; - private static final String INVARIANT_RESOURCE1_UUID = "07e266fc-49ab-4cd7-8378-ca4676f1b9ec"; - private static final String INVARIANT_RESOURCE2_UUID = "023a3f0d-1161-45ff-b4cf-8918a8ccf3ad"; - private static final String RESOURCE_INSTANCE_NAME_RESOURCE1 = "ResourceInstanceName1"; - private static final String RESOURCE_INSTANCE_NAME_RESOURCE2 = "ResourceInstanceName2"; - - @Autowired - @Qualifier("oldModelInstaller") - private CsarInstaller csarInstaller; - - @Autowired - private CldsDao cldsDao; - - @Test(expected = SdcArtifactInstallerException.class) - public void testInstallTheCsarFail() throws SdcArtifactInstallerException, SdcToscaParserException, - CsarHandlerException, IOException, InterruptedException, PolicyModelException { - CsarHandler csarHandler = Mockito.mock(CsarHandler.class); - BlueprintArtifact blueprintArtifact = Mockito.mock(BlueprintArtifact.class); - Mockito.when(blueprintArtifact.getResourceAttached()).thenReturn(Mockito.mock(IResourceInstance.class)); - Map<String, BlueprintArtifact> blueprintMap = new HashMap<>(); - blueprintMap.put("resourceid", blueprintArtifact); - Mockito.when(csarHandler.getMapOfBlueprints()).thenReturn(blueprintMap); - Mockito.when(blueprintArtifact.getDcaeBlueprint()).thenReturn( - IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/not-recognized.yaml"), - StandardCharsets.UTF_8)); - csarInstaller.installTheCsar(csarHandler); - fail("Should have raised an SdcArtifactInstallerException"); - } - - private BlueprintArtifact buildFakeBuildprintArtifact(String instanceName, String invariantResourceUuid, - String blueprintFilePath, String artifactName, String invariantServiceUuid) throws IOException { - IResourceInstance resource = Mockito.mock(IResourceInstance.class); - Mockito.when(resource.getResourceInstanceName()).thenReturn(instanceName); - Mockito.when(resource.getResourceInvariantUUID()).thenReturn(invariantResourceUuid); - BlueprintArtifact blueprintArtifact = Mockito.mock(BlueprintArtifact.class); - Mockito.when(blueprintArtifact.getDcaeBlueprint()) - .thenReturn(ResourceFileUtil.getResourceAsString(blueprintFilePath)); - Mockito.when(blueprintArtifact.getBlueprintArtifactName()).thenReturn(artifactName); - Mockito.when(blueprintArtifact.getBlueprintInvariantServiceUuid()).thenReturn(invariantServiceUuid); - Mockito.when(blueprintArtifact.getResourceAttached()).thenReturn(resource); - return blueprintArtifact; - } - - private CsarHandler buildFakeCsarHandler(String generatedName) throws IOException { - // Create fake notification - INotificationData notificationData = Mockito.mock(INotificationData.class); - Mockito.when(notificationData.getServiceVersion()).thenReturn("1.0"); - // Create fake resource in notification - CsarHandler csarHandler = Mockito.mock(CsarHandler.class); - List<IResourceInstance> listResources = new ArrayList<>(); - Mockito.when(notificationData.getResources()).thenReturn(listResources); - Map<String, BlueprintArtifact> blueprintMap = new HashMap<>(); - Mockito.when(csarHandler.getMapOfBlueprints()).thenReturn(blueprintMap); - // Create fake blueprint artifact 1 on resource1 - BlueprintArtifact blueprintArtifact = buildFakeBuildprintArtifact(RESOURCE_INSTANCE_NAME_RESOURCE1, - INVARIANT_RESOURCE1_UUID, "example/sdc/blueprint-dcae/tca.yaml", "tca.yaml", INVARIANT_SERVICE_UUID); - listResources.add(blueprintArtifact.getResourceAttached()); - blueprintMap.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact); - // Create fake blueprint artifact 2 on resource2 - blueprintArtifact = buildFakeBuildprintArtifact(RESOURCE_INSTANCE_NAME_RESOURCE2, INVARIANT_RESOURCE2_UUID, - "example/sdc/blueprint-dcae/tca_2.yaml", "tca_2.yaml", INVARIANT_SERVICE_UUID); - listResources.add(blueprintArtifact.getResourceAttached()); - blueprintMap.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact); - - // Create fake blueprint artifact 3 on resource 1 so that it's possible to - // test multiple CL deployment per Service/vnf - blueprintArtifact = buildFakeBuildprintArtifact(RESOURCE_INSTANCE_NAME_RESOURCE1, INVARIANT_RESOURCE1_UUID, - "example/sdc/blueprint-dcae/tca_3.yaml", "tca_3.yaml", INVARIANT_SERVICE_UUID); - blueprintMap.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact); - - // Build fake csarhandler - Mockito.when(csarHandler.getSdcNotification()).thenReturn(notificationData); - // Build fake csar Helper - ISdcCsarHelper csarHelper = Mockito.mock(ISdcCsarHelper.class); - Metadata data = Mockito.mock(Metadata.class); - Mockito.when(data.getValue("name")).thenReturn(generatedName); - Mockito.when(csarHelper.getServiceMetadata()).thenReturn(data); - Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(csarHelper); - return csarHandler; - } - - @Test - public void testIsCsarAlreadyDeployedTca() throws SdcArtifactInstallerException, SdcToscaParserException, - CsarHandlerException, IOException, InterruptedException, PolicyModelException { - String generatedName = RandomStringUtils.randomAlphanumeric(5); - CsarHandler csarHandler = buildFakeCsarHandler(generatedName); - assertFalse(csarInstaller.isCsarAlreadyDeployed(csarHandler)); - csarInstaller.installTheCsar(csarHandler); - assertTrue(csarInstaller.isCsarAlreadyDeployed(csarHandler)); - } - - @Test - public void testInstallTheCsarTca() throws SdcArtifactInstallerException, SdcToscaParserException, - CsarHandlerException, IOException, JSONException, InterruptedException, PolicyModelException { - String generatedName = RandomStringUtils.randomAlphanumeric(5); - CsarHandler csar = buildFakeCsarHandler(generatedName); - csarInstaller.installTheCsar(csar); - CldsModel cldsModel1 = verifyClosedLoopModelLoadedInDb(csar, "tca.yaml"); - JSONAssert.assertEquals( - IOUtils.toString(ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca.json"), - StandardCharsets.UTF_8), - cldsModel1.getPropText(), true); - CldsModel cldsModel2 = verifyClosedLoopModelLoadedInDb(csar, "tca_2.yaml"); - JSONAssert.assertEquals(IOUtils.toString( - ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca-2.json"), - StandardCharsets.UTF_8), cldsModel2.getPropText(), true); - CldsModel cldsModel3 = verifyClosedLoopModelLoadedInDb(csar, "tca_3.yaml"); - JSONAssert.assertEquals(IOUtils.toString( - ResourceFileUtil.getResourceAsStream("example/sdc/blueprint-dcae/prop-text-for-tca-3.json"), - StandardCharsets.UTF_8), cldsModel3.getPropText(), true); - } - - private CldsModel verifyClosedLoopModelLoadedInDb(CsarHandler csar, String artifactName) - throws SdcArtifactInstallerException { - - // Get the template back from DB - CldsTemplate templateFromDb = CldsTemplate.retrieve(cldsDao, CsarInstallerImpl.TEMPLATE_NAME_PREFIX - + CsarInstallerImpl.buildModelName(csar, csar.getMapOfBlueprints().get(artifactName)), false); - assertNotNull(templateFromDb); - assertNotNull(templateFromDb.getBpmnText()); - assertNotNull(templateFromDb.getImageText()); - assertNotNull(templateFromDb.getPropText()); - assertTrue(templateFromDb.getPropText().contains("global") - && templateFromDb.getPropText().contains("node_templates:")); - assertEquals(templateFromDb.getName(), CsarInstallerImpl.TEMPLATE_NAME_PREFIX - + CsarInstallerImpl.buildModelName(csar, csar.getMapOfBlueprints().get(artifactName))); - // Get the Model back from DB - CldsModel modelFromDb = CldsModel.retrieve(cldsDao, - CsarInstallerImpl.buildModelName(csar, csar.getMapOfBlueprints().get(artifactName)), true); - assertNotNull(modelFromDb); - assertNotNull(modelFromDb.getBpmnText()); - assertNotNull(modelFromDb.getImageText()); - assertNotNull(modelFromDb.getPropText()); - assertTrue(modelFromDb.getPropText().contains("policy_id")); - assertEquals(CsarInstallerImpl.buildModelName(csar, csar.getMapOfBlueprints().get(artifactName)), - modelFromDb.getName()); - assertEquals(CsarInstallerImpl.CONTROL_NAME_PREFIX, modelFromDb.getControlNamePrefix()); - return modelFromDb; - } -} diff --git a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/LoopCsarInstallerTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/LoopCsarInstallerTest.java deleted file mode 100644 index e462455fd..000000000 --- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/LoopCsarInstallerTest.java +++ /dev/null @@ -1,167 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 Nokia 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============================================ - * * Modifications copyright (c) 2019 Nokia - * =================================================================== - * - */ - -package org.onap.clamp.clds.sdc.controller.installer; - -import com.google.gson.JsonObject; - -import java.io.IOException; -import java.io.InputStream; - -import org.apache.commons.io.IOUtils; -import org.assertj.core.api.Assertions; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.clamp.clds.client.DcaeInventoryServices; -import org.onap.clamp.clds.config.sdc.BlueprintParserFilesConfiguration; -import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException; -import org.onap.clamp.clds.service.CldsService; -import org.onap.clamp.clds.service.CldsTemplateService; -import org.onap.clamp.clds.transform.XslTransformer; -import org.onap.clamp.clds.util.JsonUtils; -import org.onap.clamp.clds.util.ResourceFileUtil; -import org.onap.sdc.api.notification.INotificationData; -import org.onap.sdc.api.notification.IResourceInstance; -import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; -import org.onap.sdc.toscaparser.api.elements.Metadata; -import org.springframework.context.ApplicationContext; -import org.springframework.core.io.Resource; - -@RunWith(MockitoJUnitRunner.class) -public class LoopCsarInstallerTest { - - @Mock - private CsarHandler csarHandler; - - @Mock - private ApplicationContext applicationContext; - - @Mock - private DcaeInventoryServices dcaeInventoryServices; - - @Mock - private IResourceInstance resourceInstance; - - @Mock - private CldsService cldsService; - - @Mock - private INotificationData notificationData; - - @Mock - private Metadata metadata; - - @Mock - private ISdcCsarHelper sdcCsarHelper; - - private CsarInstallerImpl csarInstaller; - private BlueprintArtifact artifact; - - /** - * Set up method. throws: Exception - */ - @Before - public void setUp() throws Exception { - String dceaBlueprint = ResourceFileUtil.getResourceAsString("tosca/dcea_blueprint.yml"); - artifact = prepareBlueprintArtifact(dceaBlueprint); - csarInstaller = new CsarInstallerImpl(applicationContext, null, new CldsTemplateService(), cldsService, - dcaeInventoryServices, new XslTransformer()); - } - - @Test - public void shouldReturnInputParametersFromBlueprint() { - // given - String expectedBlueprintInputsText = "{\"aaiEnrichmentHost\":\"aai.onap.svc.cluster.local\"" - + ",\"aaiEnrichmentPort\":\"8443\"" + ",\"enableAAIEnrichment\":true" + ",\"dmaap_host\":\"message-router\"" - + ",\"dmaap_port\":\"3904\"" + ",\"enableRedisCaching\":false" + ",\"redisHosts\":\"dcae-redis:6379\"" - + ",\"tag_version\":" - + "\"nexus3.onap.org:10001/onap/org.onap.dcaegen2.deployments.tca-cdap-container:1.1.0\"" - + ",\"consul_host\":\"consul-server\"" + ",\"consul_port\":\"8500\",\"cbs_host\":\"{\\\"test\\\":" - + "{\\\"test\\\":\\\"test\\\"}}\",\"cbs_port\":\"10000\"" - + ",\"external_port\":\"32010\",\"policy_id\":\"AUTO_GENERATED_POLICY_ID_AT_SUBMIT\"}"; - - JsonObject expectedBlueprintInputs = JsonUtils.GSON.fromJson(expectedBlueprintInputsText, JsonObject.class); - // when - String parametersInJson = csarInstaller.getAllBlueprintParametersInJson(artifact); - // then - Assertions.assertThat(JsonUtils.GSON.fromJson(parametersInJson, JsonObject.class)) - .isEqualTo(expectedBlueprintInputs); - } - - @Test - public void shouldReturnBuildModelName() throws SdcArtifactInstallerException { - // given - String expectedModelName = "CLAMP_test_name_" + "vtest_service_version_" + "test_resource_instance_name_" - + "test_artifact_name"; - prepareMockCsarHandler("name", "test_name", "test_service_version"); - Mockito.when(resourceInstance.getResourceInstanceName()).thenReturn("test_resource_instance_name"); - // when - String actualModelName = CsarInstallerImpl.buildModelName(csarHandler, artifact); - // then - Assertions.assertThat(actualModelName).isEqualTo(expectedModelName); - } - - @Test - public void shouldReturnRightMapping() throws SdcArtifactInstallerException, IOException { - // given - String input = "[{\"blueprintKey\":\"tca_k8s\"," + "\"dcaeDeployable\":false," - + "\"files\":{\"svgXmlFilePath\":\"samplePath\",\"bpmnXmlFilePath\":\"samplePath\"}}]"; - BlueprintParserFilesConfiguration filesConfiguration = new BlueprintParserFilesConfiguration(); - filesConfiguration.setBpmnXmlFilePath("samplePath"); - filesConfiguration.setSvgXmlFilePath("samplePath"); - Resource resource = Mockito.mock(Resource.class); - InputStream inputStream = IOUtils.toInputStream(input, "UTF-8"); - Mockito.when(applicationContext.getResource(Mockito.any(String.class))).thenReturn(resource); - Mockito.when(resource.getInputStream()).thenReturn(inputStream); - csarInstaller.loadConfiguration(); - // when - BlueprintParserFilesConfiguration configuration = csarInstaller.searchForRightMapping(artifact); - - // then - Assertions.assertThat(configuration.getBpmnXmlFilePath()).isEqualTo("samplePath"); - Assertions.assertThat(configuration.getSvgXmlFilePath()).isEqualTo("samplePath"); - } - - private BlueprintArtifact prepareBlueprintArtifact(String dceaBlueprint) { - artifact = new BlueprintArtifact(); - artifact.setBlueprintArtifactName("test_artifact_name"); - artifact.setBlueprintInvariantServiceUuid("test_inv_uuid"); - artifact.setResourceAttached(resourceInstance); - artifact.setDcaeBlueprint(dceaBlueprint); - return artifact; - } - - private void prepareMockCsarHandler(String metadataNameMockInput, String metadataNameMockOutput, - String serviceVersion) { - Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(sdcCsarHelper); - Mockito.when(sdcCsarHelper.getServiceMetadata()).thenReturn(metadata); - Mockito.when(metadata.getValue(metadataNameMockInput)).thenReturn(metadataNameMockOutput); - Mockito.when(csarHandler.getSdcNotification()).thenReturn(notificationData); - Mockito.when(notificationData.getServiceVersion()).thenReturn(serviceVersion); - } -}
\ No newline at end of file |