Search in sources :

Example 1 with NameGenRequest

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

the class NamingRequestObjectBuilder method nameGenRequestMapper.

public NameGenRequest nameGenRequestMapper(List<Element> elements) {
    NameGenRequest nameGenRequest = new NameGenRequest();
    nameGenRequest.setElements(elements);
    return nameGenRequest;
}
Also used : NameGenRequest(org.onap.namingservice.model.NameGenRequest)

Example 2 with NameGenRequest

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

the class NamingClient method postNameGenRequest.

public String postNameGenRequest(NameGenRequest request) throws BadResponseException, IOException {
    String targetUrl = env.getProperty(ENDPOINT);
    HttpHeaders headers = setHeaders(env.getProperty(AUTH));
    logger.info("Sending postNameGenRequest to url: {}", targetUrl);
    HttpEntity<NameGenRequest> requestEntity = new HttpEntity<>(request, headers);
    ResponseEntity<NameGenResponse> response;
    try {
        response = restTemplate.postForEntity(targetUrl, requestEntity, NameGenResponse.class);
    } catch (HttpStatusCodeException e) {
        throw new BadResponseException(namingClientResponseValidator.formatError(e));
    }
    return namingClientResponseValidator.validateNameGenResponse(response);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) NameGenResponse(org.onap.namingservice.model.NameGenResponse) HttpEntity(org.springframework.http.HttpEntity) BadResponseException(org.onap.so.client.exception.BadResponseException) NameGenRequest(org.onap.namingservice.model.NameGenRequest) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException)

Example 3 with NameGenRequest

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

the class NamingClientIT method assignNameGenRequest.

@Test
public void assignNameGenRequest() throws BadResponseException, IOException {
    wireMockServer.stubFor(post(urlPathEqualTo("/web/service/v1/genNetworkElementName")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("NamingClient/AssignResponse.json").withStatus(HttpStatus.SC_ACCEPTED)));
    NameGenRequest request = assignSetup();
    String response = client.postNameGenRequest(request);
    assertTrue(response.equals("$vnf-name"));
}
Also used : NameGenRequest(org.onap.namingservice.model.NameGenRequest) Test(org.junit.Test) BaseIntegrationTest(org.onap.so.BaseIntegrationTest)

Example 4 with NameGenRequest

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

the class NamingClientIT method assignSetup.

public NameGenRequest assignSetup() throws JsonProcessingException {
    NameGenRequest request = new NameGenRequest();
    List<Element> elements = new ArrayList<>();
    Element testElement = new Element();
    testElement = requestBuilder.elementMapper("SomeUniqueValue", "SDNC_Policy.Config_MS_1806SRIOV_VNATJson.4.xml", "VNF", "nfNamingCode", "vnf_name");
    elements.add(testElement);
    request = requestBuilder.nameGenRequestMapper(elements);
    return request;
}
Also used : NameGenRequest(org.onap.namingservice.model.NameGenRequest) Element(org.onap.namingservice.model.Element) ArrayList(java.util.ArrayList)

Example 5 with NameGenRequest

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

the class NamingClientIT method assignNameGenRequestError.

@Test
public void assignNameGenRequestError() throws BadResponseException, IOException {
    wireMockServer.stubFor(post(urlPathEqualTo("/web/service/v1/genNetworkElementName")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("NamingClient/ErrorResponse.json").withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
    thrown.expect(BadResponseException.class);
    thrown.expectMessage("Error from Naming Service: External Key is required and must be unique");
    NameGenRequest request = assignSetup();
    client.postNameGenRequest(request);
}
Also used : NameGenRequest(org.onap.namingservice.model.NameGenRequest) Test(org.junit.Test) BaseIntegrationTest(org.onap.so.BaseIntegrationTest)

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