@Before
public void setup() {
objectMapper = new ObjectMapper();
- template = new Template("getNbr", "ran-network", "sample", "get");
+ template = new Template("getNbr", "ran-network", "sample", "get", true);
}
@Test
public void testCreateTemplate() throws Exception {
- final TemplateRequest templateRequest = new TemplateRequest("getNbr", "ran-network", "sample", "get");
+ final TemplateRequest templateRequest = new TemplateRequest("getNbr", "ran-network", "sample", "get", true);
final String templateJson = objectMapper.writeValueAsString(templateRequest);
Mockito.when(templateBusinessLogic.createTemplate(ArgumentMatchers.any()))
.thenReturn(template);
import java.util.Arrays;
import org.onap.cps.tbdmt.exception.CpsClientException;
import org.onap.cps.tbdmt.model.AppConfiguration;
+import org.onap.cps.tbdmt.model.CpsConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
@Component
public class CpsRestClient {
- private static final String NODES_API_PATH = "/anchors/{anchor}/nodes";
+ private static final String NODES_API_PATH = "/anchors/{anchor}/node";
private static final String QUERY_API_PATH = "/anchors/{anchor}/nodes/query";
* @return result Response string from CPS
*/
public String fetchNode(final String anchor, final String xpath,
- final String requestType) throws CpsClientException {
+ final String requestType, final Boolean includeDescendants) throws CpsClientException {
final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>();
- queryParams.add("cpsPath", xpath);
- String uri = buildCpsUrl(NODES_API_PATH, anchor, queryParams);
- if ("query".equals(requestType)) {
- uri = buildCpsUrl(QUERY_API_PATH, anchor, queryParams);
- }
+ queryParams.add("xpath", xpath);
+ queryParams.add("include-descendants", includeDescendants.toString());
+
+ final CpsConfiguration cpsConfiguration = "cpsCore".equals(appConfiguration.getCpsClient())
+ ? appConfiguration.getCpsCoreConfiguration() : appConfiguration.getNcmpConfiguration();
+
+ final String path = "query".equals(requestType) ? QUERY_API_PATH : NODES_API_PATH;
+ final String uri = buildCpsUrl(cpsConfiguration.getUrl(), path, anchor, queryParams);
final HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
+
+ headers.setBasicAuth(cpsConfiguration.getUsername(), cpsConfiguration.getPassword());
final HttpEntity<String> entity = new HttpEntity<>(headers);
ResponseEntity<String> responseEntity = null;
}
}
- private String buildCpsUrl(final String path, final String anchor,
+ private String buildCpsUrl(final String baseUrl, final String path, final String anchor,
final MultiValueMap<String, String> queryParams) {
- final String baseUrl = appConfiguration.getXnfProxyUrl();
return UriComponentsBuilder
.fromHttpUrl(baseUrl)
@ConfigurationProperties(prefix = "app")
public class AppConfiguration {
- private String xnfProxyUrl;
+ private CpsConfiguration cpsCoreConfiguration;
+
+ private CpsConfiguration ncmpConfiguration;
+
+ private String cpsClient;
+
private Map<String, String> schemaToAnchor;
@Bean
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 Wipro Limited.
+ * ================================================================================
+ * 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.cps.tbdmt.model;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class CpsConfiguration {
+
+ private String url;
+
+ private String username;
+
+ private String password;
+
+}
private String requestType;
+ private Boolean includeDescendants;
+
}
@NotEmpty(message = "request type missing")
private String requestType;
+ private Boolean includeDescendants;
}
final String xpath = generateXpath(template.getXpathTemplate(), inputParameters);
try {
- return cpsRestClient.fetchNode(anchor, xpath, template.getRequestType());
+ return cpsRestClient.fetchNode(anchor, xpath, template.getRequestType(), template.getIncludeDescendants());
} catch (final CpsClientException e) {
throw new ExecuteException(e.getLocalizedMessage());
}
*/
public Template createTemplate(final TemplateRequest templateRequest) {
final Template template = new Template(templateRequest.getTemplateId(),
- templateRequest.getModel(),
- templateRequest.getXpathTemplate(), templateRequest.getRequestType());
+ templateRequest.getModel(), templateRequest.getXpathTemplate(),
+ templateRequest.getRequestType(), templateRequest.getIncludeDescendants());
return templateRepository.save(template);
}
@Test
public void testFetchNode() throws Exception {
- final String uri = "http://localhost:8000/anchors/coverage-area-onap/nodes?cpsPath=sample";
+ final String uri = "http://localhost:8000/anchors/coverage-area-onap/node?xpath=sample&include-descendants=true";
Mockito.when(restTemplate.exchange(ArgumentMatchers.eq(uri),
ArgumentMatchers.any(HttpMethod.class),
ArgumentMatchers.any(),
ArgumentMatchers.<Class<String>>any()))
.thenReturn(response);
- assertEquals("sample response", cpsRestClient.fetchNode("coverage-area-onap", "sample", "get"));
+ assertEquals("sample response", cpsRestClient.fetchNode("coverage-area-onap", "sample", "get", true));
final ResponseEntity<String> errorResponse = new ResponseEntity<>("sample response",
responseHeaders, HttpStatus.NOT_FOUND);
.thenReturn(errorResponse);
exception.expect(CpsClientException.class);
exception.expectMessage("Response code from CPS other than 200: 404");
- cpsRestClient.fetchNode("coverage-area-onap", "sample", "get");
+ cpsRestClient.fetchNode("coverage-area-onap", "sample", "get", true);
}
@Test
public void testQueryApi() throws Exception {
- final String uri = "http://localhost:8000/anchors/coverage-area-onap/nodes/query?cpsPath=sample";
+ final String uri = "http://localhost:8000/anchors/coverage-area-onap/nodes/query?xpath=sample&include-descendants=true";
Mockito.when(restTemplate.exchange(ArgumentMatchers.eq(uri),
ArgumentMatchers.any(HttpMethod.class),
ArgumentMatchers.any(),
ArgumentMatchers.<Class<String>>any()))
.thenReturn(response);
- assertEquals("sample response", cpsRestClient.fetchNode("coverage-area-onap", "sample", "query"));
+ assertEquals("sample response", cpsRestClient.fetchNode("coverage-area-onap", "sample", "query", true));
}
@Test
.thenThrow(new RestClientException("Connection refused"));
exception.expect(CpsClientException.class);
exception.expectMessage("Connection refused");
- cpsRestClient.fetchNode("coverage-area-onap", "sample", "get");
+ cpsRestClient.fetchNode("coverage-area-onap", "sample", "get", true);
}
}
request = new ExecutionRequest(input);
final String xpathTemplate = "/ran-coverage-area/pLMNIdList[@mcc='310' and @mnc='410']"
+ "/coverage-area[@coverageArea='{{coverageArea}}']";
- template = new Template("getNbr", "ran-network", xpathTemplate, "get");
- queryTemplate = new Template("getNbr", "ran-network", xpathTemplate, "query");
+ template = new Template("getNbr", "ran-network", xpathTemplate, "get", true);
+ queryTemplate = new Template("getNbr", "ran-network", xpathTemplate, "query", true);
}
@Test
final String resultString = "[{\"key\": \"value\"}]";
Mockito.when(cpsRestClient
.fetchNode("ran-network", "/ran-coverage-area/pLMNIdList[@mcc='310' and @mnc='410']"
- + "/coverage-area[@coverageArea='Zone 1']", "get"))
+ + "/coverage-area[@coverageArea='Zone 1']", "get", true))
.thenReturn(resultString);
Mockito.when(templateRepository.findById(ArgumentMatchers.any()))
.thenReturn(Optional.of(template));
final String exceptionMessage = "Response from CPS other than 200: 404";
Mockito.when(cpsRestClient
.fetchNode("ran-network", "/ran-coverage-area/pLMNIdList[@mcc='310' and @mnc='410']"
- + "/coverage-area[@coverageArea='Zone 1']", "get"))
+ + "/coverage-area[@coverageArea='Zone 1']", "get", true))
.thenThrow(new CpsClientException(exceptionMessage));
Mockito.when(templateRepository.findById(ArgumentMatchers.any()))
.thenReturn(Optional.of(template));
exception.expectMessage(exceptionMessage);
executionBusinessLogic.executeTemplate("ran-network", "getNbr", request);
- final Template template1 = new Template("getNbr", "ran-net", "sample", "get");
+ final Template template1 = new Template("getNbr", "ran-net", "sample", "get", true);
Mockito.when(templateRepository.findById(ArgumentMatchers.any()))
.thenReturn(Optional.of(template1));
exception.expect(ExecuteException.class);
@Test
public void testExecuteTemplateNoAnchor() {
- final Template template = new Template("getNbr", "ran-net", "sample", "get");
+ final Template template = new Template("getNbr", "ran-net", "sample", "get", true);
Mockito.when(templateRepository.findById(ArgumentMatchers.any()))
.thenReturn(Optional.of(template));
exception.expect(ExecuteException.class);
final String resultString = "[{\"key\": \"value\"}]";
Mockito.when(cpsRestClient
.fetchNode("ran-network", "/ran-coverage-area/pLMNIdList[@mcc='310' and @mnc='410']"
- + "/coverage-area[@coverageArea='Zone 1']", "query"))
+ + "/coverage-area[@coverageArea='Zone 1']", "query", true))
.thenReturn(resultString);
Mockito.when(templateRepository.findById(ArgumentMatchers.any()))
.thenReturn(Optional.of(queryTemplate));
@Before
public void setup() {
- template = new Template("getNbr", "ran-network", "sample", "get");
+ template = new Template("getNbr", "ran-network", "sample", "get", true);
final TemplateKey templateKey = new TemplateKey("getNbr", "ran-network");
}
@Test
public void testCreateTemplate() throws Exception {
- final TemplateRequest templateRequest = new TemplateRequest("getNbr", "ran-network", "sample", "get");
+ final TemplateRequest templateRequest = new TemplateRequest("getNbr", "ran-network", "sample", "get", true);
Mockito.when(templateRepository.save(ArgumentMatchers.any())).thenReturn(template);
assertEquals(template, templateBusinessLogic.createTemplate(templateRequest));
}
-app.xnfProxyUrl=http://localhost:8000/
+app.cpsCoreConfiguration.url=http://localhost:8000/
+app.cpsCoreConfiguration.username=cpsuser
+app.cpsCoreConfiguration.password=cpspass
+app.ncmpConfiguration.url=http://localhost:8000/
+app.ncmpConfiguration.username=cpsuser
+app.ncmpConfiguration.password=cpspass
+app.cpsClient=cpsCore
app.schemaToAnchor.ran-coverage-area=coverage-area-onap
app.schemaToAnchor.ran-network=ran-network
\ No newline at end of file
use_jdbc_metadata_defaults: false
database-platform: org.hibernate.dialect.PostgreSQLDialect
app:
- xnfProxyUrl: http://localhost:8000/
+ cpsCoreConfiguration:
+ url: http://192.168.1.5:8883/cps/api/v1/dataspaces/E2EDemo
+ username: cpsuser
+ password: cpsr0cks!
+ ncmpConfiguration:
+ url: http://192.168.1.5:8883/cps/api/v1
+ username: cpsuser
+ password: cpsr0cks!
+ cpsClient: cpsCore
schemaToAnchor:
ran-coverage-area: coverage-area-onap
+ e2e-cavsta-schemaset: e2e-cavsta1
+