aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authorxuegao <xg353y@intl.att.com>2019-11-08 13:10:36 +0100
committerxuegao <xg353y@intl.att.com>2019-11-18 10:41:47 +0100
commit289e8e1f1858e970f92b50a1e601521edeefd44f (patch)
tree78246ad3b62c744626811949aea653d0ee7c8e58 /src/test/java
parent77b0be1b734ae1f785fb35a59387ac5fbcf19266 (diff)
Create Service object
User Service object to store loop service and resource realted info. Issue-ID: CLAMP-545 Change-Id: I0df6f5d43d7e0575346e02a27bca5c0b5ecdb0a0 Signed-off-by: xuegao <xg353y@intl.att.com>
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java2
-rw-r--r--src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java9
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java4
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopToJsonTest.java28
-rw-r--r--src/test/java/org/onap/clamp/loop/ServiceTest.java55
-rw-r--r--src/test/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilderTest.java5
6 files changed, 95 insertions, 8 deletions
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 072d57712..40cc0650e 100644
--- a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java
@@ -104,7 +104,6 @@ public class CldsServiceItCase {
@Test
public void testCldsInfoAuthorized() throws Exception {
- Authentication authentication;
List<GrantedAuthority> authList = new LinkedList<GrantedAuthority>();
authList.add(new SimpleGrantedAuthority("permission-type-cl-manage|dev|*"));
authList.add(new SimpleGrantedAuthority("permission-type-cl|dev|read"));
@@ -113,6 +112,7 @@ public class CldsServiceItCase {
authList.add(new SimpleGrantedAuthority("permission-type-template|dev|update"));
authList.add(new SimpleGrantedAuthority("permission-type-filter-vf|dev|*"));
authList.add(new SimpleGrantedAuthority("permission-type-cl-event|dev|*"));
+ Authentication authentication;
authentication = new UsernamePasswordAuthenticationToken(new User("admin", "", authList), "", authList);
Mockito.when(securityContext.getAuthentication()).thenReturn(authentication);
diff --git a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
index fbf1f2079..e3271c7a6 100644
--- a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
+++ b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
@@ -202,10 +202,13 @@ public class CsarInstallerItCase {
assertThat(loop.getGlobalPropertiesJson().get("dcaeDeployParameters")).isNotNull();
assertThat(loop.getMicroServicePolicies()).hasSize(1);
assertThat(loop.getOperationalPolicies()).hasSize(1);
- assertThat(loop.getModelPropertiesJson().get("serviceDetails")).isNotNull();
- assertThat(loop.getModelPropertiesJson().get("resourceDetails")).isNotNull();
+ assertThat(loop.getModelService().getServiceUuid()).isEqualTo("63cac700-ab9a-4115-a74f-7eac85e3fce0");
JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/model-properties.json"),
- JsonUtils.GSON.toJson(loop.getModelPropertiesJson()), true);
+ JsonUtils.GSON_JPA_MODEL.toJson(loop.getModelService()), true);
+ JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/service-details.json"),
+ JsonUtils.GSON_JPA_MODEL.toJson(loop.getModelService().getServiceDetails()), true);
+ JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/resource-details.json"),
+ JsonUtils.GSON_JPA_MODEL.toJson(loop.getModelService().getResourceDetails()), true);
assertThat(((MicroServicePolicy) (loop.getMicroServicePolicies().toArray()[0])).getModelType()).isNotEmpty();
loop = loopsRepo
diff --git a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
index 1fedc9abe..28a92e371 100644
--- a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
+++ b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
@@ -347,8 +347,8 @@ public class LoopServiceTestItCase {
saveTestLoopToDb();
assertThat(microServicePolicyService.isExisting("policyName")).isFalse();
MicroServicePolicy microServicePolicy = new MicroServicePolicy("policyName", "",
- "tosca_definitions_version: tosca_simple_yaml_1_0_0", false,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
+ "tosca_definitions_version: tosca_simple_yaml_1_0_0", false,
+ JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
loopService.updateMicroservicePolicy(EXAMPLE_LOOP_NAME, microServicePolicy);
assertThat(microServicePolicyService.isExisting("policyName")).isTrue();
}
diff --git a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
index 3010fe50b..b68bf48a0 100644
--- a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
+++ b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
@@ -29,7 +29,9 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
+import com.google.gson.JsonSyntaxException;
import java.io.IOException;
import java.util.HashSet;
@@ -41,6 +43,7 @@ import org.onap.clamp.clds.util.ResourceFileUtil;
import org.onap.clamp.loop.components.external.PolicyComponent;
import org.onap.clamp.loop.log.LogType;
import org.onap.clamp.loop.log.LoopLog;
+import org.onap.clamp.loop.service.Service;
import org.onap.clamp.policy.microservice.MicroServicePolicy;
import org.onap.clamp.policy.operational.OperationalPolicy;
import org.skyscreamer.jsonassert.JSONAssert;
@@ -54,7 +57,7 @@ public class LoopToJsonTest {
}
private Loop getLoop(String name, String svgRepresentation, String blueprint, String globalPropertiesJson,
- String dcaeId, String dcaeUrl, String dcaeBlueprintId) {
+ String dcaeId, String dcaeUrl, String dcaeBlueprintId) throws JsonSyntaxException, IOException {
Loop loop = new Loop(name, blueprint, svgRepresentation);
loop.setGlobalPropertiesJson(new Gson().fromJson(globalPropertiesJson, JsonObject.class));
loop.setLastComputedState(LoopState.DESIGN);
@@ -116,6 +119,29 @@ public class LoopToJsonTest {
}
@Test
+ public void loopServiceTest() throws IOException {
+ Loop loopTest2 = getLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}",
+ "123456789", "https://dcaetest.org", "UUID-blueprint");
+
+ JsonObject jsonModel = new GsonBuilder().create()
+ .fromJson(ResourceFileUtil.getResourceAsString("tosca/model-properties.json"), JsonObject.class);
+ Service service = new Service(jsonModel.get("serviceDetails").getAsJsonObject(),
+ jsonModel.get("resourceDetails").getAsJsonObject());
+ loopTest2.setModelService(service);
+
+ String jsonSerialized = JsonUtils.GSON_JPA_MODEL.toJson(loopTest2);
+ assertThat(jsonSerialized).isNotNull().isNotEmpty();
+ System.out.println(jsonSerialized);
+ JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/loop.json"),
+ jsonSerialized, true);
+
+ Loop loopTestDeserialized = JsonUtils.GSON_JPA_MODEL.fromJson(jsonSerialized, Loop.class);
+ assertNotNull(loopTestDeserialized);
+ assertThat(loopTestDeserialized).isEqualToIgnoringGivenFields(loopTest2, "modelService",
+ "svgRepresentation", "blueprint", "components");
+ }
+
+ @Test
public void createPoliciesPayloadPdpGroupTest() throws IOException {
Loop loopTest = getLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}",
"123456789", "https://dcaetest.org", "UUID-blueprint");
diff --git a/src/test/java/org/onap/clamp/loop/ServiceTest.java b/src/test/java/org/onap/clamp/loop/ServiceTest.java
new file mode 100644
index 000000000..45de5385e
--- /dev/null
+++ b/src/test/java/org/onap/clamp/loop/ServiceTest.java
@@ -0,0 +1,55 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 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.loop;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.google.gson.JsonObject;
+
+import org.junit.Test;
+import org.onap.clamp.clds.util.JsonUtils;
+import org.onap.clamp.loop.service.Service;
+
+public class ServiceTest {
+
+ @Test
+ public void equalMethodTest() {
+ String serviceStr1 = "{\"name\": \"vLoadBalancerMS\", \"UUID\": \"63cac700-ab9a-4115-a74f-7eac85e3fce0\"}";
+ String serviceStr2 = "{\"name\": \"vLoadBalancerMS2\", \"UUID\": \"63cac700-ab9a-4115-a74f-7eac85e3fce0\"}";
+ String serviceStr3 = "{\"name\": \"vLoadBalancerMS\",\"UUID\": \"63cac700-ab9a-4115-a74f-7eac85e3fc11\"}";
+ String resourceStr = "{\"CP\": {}}";
+
+ Service service1 = new Service(JsonUtils.GSON.fromJson(serviceStr1, JsonObject.class),
+ JsonUtils.GSON.fromJson(resourceStr, JsonObject.class));
+
+ Service service2 = new Service(JsonUtils.GSON.fromJson(serviceStr2, JsonObject.class), null);
+
+ Service service3 = new Service(JsonUtils.GSON.fromJson(serviceStr3, JsonObject.class),
+ JsonUtils.GSON.fromJson(resourceStr, JsonObject.class));
+
+ assertThat(service1.equals(service2)).isEqualTo(true);
+ assertThat(service1.equals(service3)).isEqualTo(false);
+ }
+
+}
diff --git a/src/test/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilderTest.java b/src/test/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilderTest.java
index 904525bea..673ac323d 100644
--- a/src/test/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilderTest.java
+++ b/src/test/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilderTest.java
@@ -32,6 +32,7 @@ import java.io.IOException;
import org.junit.Test;
import org.onap.clamp.clds.util.ResourceFileUtil;
+import org.onap.clamp.loop.service.Service;
import org.skyscreamer.jsonassert.JSONAssert;
public class OperationalPolicyRepresentationBuilderTest {
@@ -40,8 +41,10 @@ public class OperationalPolicyRepresentationBuilderTest {
public void testOperationalPolicyPayloadConstruction() throws IOException {
JsonObject jsonModel = new GsonBuilder().create()
.fromJson(ResourceFileUtil.getResourceAsString("tosca/model-properties.json"), JsonObject.class);
+ Service service = new Service(jsonModel.get("serviceDetails").getAsJsonObject(),
+ jsonModel.get("resourceDetails").getAsJsonObject());
- JsonObject jsonSchema = OperationalPolicyRepresentationBuilder.generateOperationalPolicySchema(jsonModel);
+ JsonObject jsonSchema = OperationalPolicyRepresentationBuilder.generateOperationalPolicySchema(service);
assertThat(jsonSchema).isNotNull();