2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.be.nodeFilter;
19 import com.fasterxml.jackson.databind.DeserializationFeature;
20 import com.fasterxml.jackson.databind.ObjectMapper;
21 import fj.data.Either;
22 import org.junit.Test;
23 import org.mockito.Mockito;
24 import org.openecomp.sdc.be.auditing.impl.AuditingManager;
25 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
26 import org.openecomp.sdc.be.impl.ComponentsUtils;
27 import org.openecomp.sdc.be.impl.ServiceFilterUtils;
28 import org.openecomp.sdc.be.model.ComponentInstance;
29 import org.openecomp.sdc.be.model.User;
30 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
31 import org.openecomp.sdc.be.ui.model.UIConstraint;
32 import org.openecomp.sdc.exception.ResponseFormat;
34 import java.io.ByteArrayOutputStream;
35 import java.io.IOException;
36 import java.util.Arrays;
39 import static org.junit.Assert.assertFalse;
40 import static org.junit.Assert.assertNotNull;
41 import static org.junit.Assert.assertTrue;
43 public class ServiceFilterUtilsCIChangeTest extends BaseServiceFilterUtilsTest {
47 public void checkComponentInstanceIsFound() {
48 Set<String> nodesFiltersToBeDeleted = getNodeFiltersToBeDeleted(CI_NAME);
49 assertNotNull(nodesFiltersToBeDeleted);
50 assertTrue(nodesFiltersToBeDeleted.contains(CI_NAME));
53 private Set<String> getNodeFiltersToBeDeleted(String inCiName) {
54 requirementNodeFilterPropertyDataDefinition
55 .setConstraints(Arrays.asList("mem_size:\n" + " equal:\n" + " get_property: ["+CI_NAME+", some static]\n"));
56 ComponentInstance ci = new ComponentInstance();
58 return ServiceFilterUtils.getNodesFiltersToBeDeleted(service, ci);
62 public void checkComponentInstanceIsNotFound() {
63 Set<String> nodesFiltersToBeDeleted = getNodeFiltersToBeDeleted(CI_NAME + " aaa bbb");
64 assertNotNull(nodesFiltersToBeDeleted);
65 assertTrue(nodesFiltersToBeDeleted.isEmpty());
66 assertFalse(nodesFiltersToBeDeleted.contains(CI_NAME));
70 public void testServiceConstraintPairSerialization() throws IOException {
71 UIConstraint uiConstraint =new UIConstraint();
72 ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
73 mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
74 assertTrue(mapper.canSerialize(uiConstraint.getClass()));
76 try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream() ) {
77 mapper.writeValue(outputStream, uiConstraint);
78 data = outputStream.toString();
82 final AuditingManager mock = Mockito.mock(AuditingManager.class);
83 final Either<UIConstraint, ResponseFormat> serviceConstraintPairResponseFormatEither =
84 new ComponentsUtils(mock)
85 .convertJsonToObjectUsingObjectMapper(data, new User(), UIConstraint.class,
86 AuditingActionEnum.ADD_GROUPING, ComponentTypeEnum.SERVICE);
87 assertTrue(serviceConstraintPairResponseFormatEither.isLeft());