2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
24 package org.onap.clamp.clds.model.dcae;
26 import static org.assertj.core.api.Assertions.assertThat;
27 import static org.junit.Assert.assertEquals;
29 import java.util.HashSet;
32 import org.apache.camel.CamelContext;
33 import org.apache.camel.Exchange;
34 import org.apache.camel.builder.ExchangeBuilder;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.onap.clamp.clds.Application;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.boot.test.context.SpringBootTest;
41 import org.springframework.test.context.junit4.SpringRunner;
43 @RunWith(SpringRunner.class)
44 @SpringBootTest(classes = Application.class)
45 public class DcaeInventoryResponseCacheTestItCase {
47 public static DcaeInventoryCache inventoryCache = new DcaeInventoryCache();
50 CamelContext camelContext;
53 * Initialize the responses.
56 public static void createExample() {
57 DcaeInventoryResponse response1 = new DcaeInventoryResponse();
58 response1.setAsdcServiceId("id1");
59 response1.setAsdcResourceId("0");
60 DcaeInventoryResponse response2 = new DcaeInventoryResponse();
61 response2.setAsdcServiceId("id1");
62 response2.setAsdcResourceId("1");
63 DcaeInventoryResponse response3 = new DcaeInventoryResponse();
64 response3.setAsdcServiceId("id1");
65 response3.setAsdcResourceId("2");
66 DcaeInventoryResponse response4 = new DcaeInventoryResponse();
67 response4.setAsdcServiceId("id2");
68 response4.setAsdcResourceId("0");
69 DcaeInventoryResponse response5 = new DcaeInventoryResponse();
70 response5.setAsdcServiceId("id2");
71 response5.setAsdcResourceId("1");
73 inventoryCache.addDcaeInventoryResponse(response1);
74 inventoryCache.addDcaeInventoryResponse(response3);
75 inventoryCache.addDcaeInventoryResponse(response2);
76 inventoryCache.addDcaeInventoryResponse(response4);
77 inventoryCache.addDcaeInventoryResponse(response5);
81 public void testGetAllLoopIds() {
82 assertThat(inventoryCache.getAllLoopIds().size()).isEqualTo(2);
86 public void testGetAllBlueprintsPerLoopId() {
88 for (DcaeInventoryResponse inventoryResponse : inventoryCache.getAllBlueprintsPerLoopId("id1")) {
89 assertThat(Integer.valueOf(inventoryResponse.getAsdcResourceId())).isEqualTo(value++);
93 for (DcaeInventoryResponse inventoryResponse : inventoryCache.getAllBlueprintsPerLoopId("id2")) {
94 assertThat(Integer.valueOf(inventoryResponse.getAsdcResourceId())).isEqualTo(value++);
99 public void testDcaeInventoryResponse() {
100 Exchange exchange = ExchangeBuilder.anExchange(camelContext).build();
101 Exchange exchangeResponse = camelContext.createProducerTemplate()
102 .send("direct:get-all-dcae-blueprint-inventory", exchange);
103 assertThat(exchangeResponse.getIn().getHeader("CamelHttpResponseCode")).isEqualTo(200);
104 Set<DcaeInventoryResponse> blueprint = inventoryCache.getAllBlueprintsPerLoopId("testAsdcServiceId");
105 assertThat(blueprint.size()).isEqualTo(2);
107 DcaeInventoryResponse response1 = new DcaeInventoryResponse();
108 response1.setAsdcResourceId("0");
109 response1.setTypeName("testTypeName");
110 response1.setAsdcServiceId("testAsdcServiceId");
111 response1.setBlueprintTemplate("testBlueprintTemplate");
112 response1.setTypeId("testtypeId");
113 DcaeInventoryResponse response2 = new DcaeInventoryResponse();
114 response2.setAsdcResourceId("1");
115 response2.setTypeName("testTypeName2");
116 response2.setAsdcServiceId("testAsdcServiceId");
117 response2.setBlueprintTemplate("testBlueprintTemplate2");
118 response2.setTypeId("testtypeId2");
120 Set<DcaeInventoryResponse> expectedBlueprint = new HashSet<>();
121 expectedBlueprint.add(response1);
122 expectedBlueprint.add(response2);
124 assertEquals(blueprint, expectedBlueprint);