Search in sources :

Example 6 with NameGenRequest

use of org.onap.namingservice.model.NameGenRequest in project so by onap.

the class NamingServiceResourcesTest method generateInstanceGroupNameTest.

@Test
public void generateInstanceGroupNameTest() throws Exception {
    NameGenResponse name = new NameGenResponse();
    ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK);
    Element element = new Element();
    NameGenRequest req = new NameGenRequest();
    doReturn(element).when(MOCK_namingRequestObjectBuilder).elementMapper(isA(String.class), isA(String.class), isA(String.class), isA(String.class), isA(String.class));
    doReturn("generatedInstanceGroupName").when(MOCK_namingClient).postNameGenRequest(isA(NameGenRequest.class));
    doReturn(req).when(MOCK_namingRequestObjectBuilder).nameGenRequestMapper(isA(List.class));
    String generatedName = namingServiceResources.generateInstanceGroupName(instanceGroup, "policyInstanceName", "nfNamingCode");
    verify(MOCK_namingClient, times(1)).postNameGenRequest(any(NameGenRequest.class));
    assertEquals(generatedName, "generatedInstanceGroupName");
}
Also used : NameGenResponse(org.onap.namingservice.model.NameGenResponse) ResponseEntity(org.springframework.http.ResponseEntity) Element(org.onap.namingservice.model.Element) NameGenRequest(org.onap.namingservice.model.NameGenRequest) List(java.util.List) Test(org.junit.Test)

Example 7 with NameGenRequest

use of org.onap.namingservice.model.NameGenRequest in project so by onap.

the class NamingRequestObjectBuilderTest method nameGenRequestMapper.

@Test
public void nameGenRequestMapper() {
    // Expected NameGenRequest
    NameGenRequest expected = new NameGenRequest();
    List<Element> elements = new ArrayList<>();
    Element element = new Element();
    element.setExternalKey(instanceGroupId);
    element.setPolicyInstanceName(policyInstanceName);
    element.setNamingType(namingType);
    element.setResourceName(instanceGroupName);
    element.setNamingIngredientsZeroOrMore(nfNamingCode);
    elements.add(element);
    expected.setElements(elements);
    // Actual NameGenRequest
    NameGenRequest actual = mapper.nameGenRequestMapper(elements);
    assertThat(actual, sameBeanAs(expected));
}
Also used : NameGenRequest(org.onap.namingservice.model.NameGenRequest) Element(org.onap.namingservice.model.Element) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with NameGenRequest

use of org.onap.namingservice.model.NameGenRequest in project so by onap.

the class NamingServiceResourcesTest method generateServiceInstanceNameTest.

@Test
public void generateServiceInstanceNameTest() throws Exception {
    NameGenRequest req = new NameGenRequest();
    doReturn("generatedServiceInstanceName").when(MOCK_namingClient).postNameGenRequest(isA(NameGenRequest.class));
    doReturn(req).when(MOCK_namingRequestObjectBuilder).nameGenRequestMapper(isA(List.class));
    NamingRequestObject nrObject = new NamingRequestObject();
    nrObject.setExternalKeyValue("testExternalKey");
    nrObject.setNamingTypeValue(NamingServiceConstants.NAMING_TYPE_SERVICE);
    nrObject.setResourceNameValue(NamingServiceConstants.RESOURCE_NAME_SERVICE_INSTANCE_NAME);
    nrObject.setPolicyInstanceNameValue(execution.getVariable("policyInstanceName"));
    nrObject.setServiceModelNameValue("testServiceInstanceModelName");
    nrObject.setModelVersionValue("testServiceInstanceModelVersion");
    nrObject.setZoneIdValue(execution.getVariable("zoneId"));
    String generatedName = namingServiceResources.generateServiceInstanceName(nrObject);
    verify(MOCK_namingClient, times(1)).postNameGenRequest(any(NameGenRequest.class));
    assertEquals("generatedServiceInstanceName", generatedName);
}
Also used : NameGenRequest(org.onap.namingservice.model.NameGenRequest) List(java.util.List) NamingRequestObject(org.onap.so.client.namingservice.NamingRequestObject) Test(org.junit.Test)

Aggregations

NameGenRequest (org.onap.namingservice.model.NameGenRequest)8 Test (org.junit.Test)5 Element (org.onap.namingservice.model.Element)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 NameGenResponse (org.onap.namingservice.model.NameGenResponse)2 BaseIntegrationTest (org.onap.so.BaseIntegrationTest)2 BadResponseException (org.onap.so.client.exception.BadResponseException)1 NamingRequestObject (org.onap.so.client.namingservice.NamingRequestObject)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1 HttpStatusCodeException (org.springframework.web.client.HttpStatusCodeException)1