2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.components;
23 import org.junit.Before;
24 import org.junit.BeforeClass;
25 import org.junit.Test;
26 import org.mockito.InjectMocks;
27 import org.mockito.Mockito;
28 import org.mockito.MockitoAnnotations;
29 import org.openecomp.sdc.be.auditing.impl.AuditingManager;
30 import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
31 import org.openecomp.sdc.be.config.ConfigurationManager;
32 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
33 import org.openecomp.sdc.be.impl.ComponentsUtils;
34 import org.openecomp.sdc.be.model.GroupDefinition;
35 import org.openecomp.sdc.be.model.User;
36 import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
37 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
38 import org.openecomp.sdc.be.model.operations.impl.GroupOperation;
39 import org.openecomp.sdc.common.api.ConfigurationSource;
40 import org.openecomp.sdc.common.api.Constants;
41 import org.openecomp.sdc.common.impl.ExternalConfiguration;
42 import org.openecomp.sdc.common.impl.FSConfigurationSource;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
46 import javax.servlet.ServletContext;
48 import static org.mockito.Mockito.when;
50 * tests GroupBusinessLogic class
54 public class GroupBusinessLogicTest {
56 private static final Logger log = LoggerFactory.getLogger(ServiceBusinessLogicTest.class);
57 ComponentsUtils componentsUtils;
58 final ServletContext servletContext = Mockito.mock(ServletContext.class);
59 private static IGraphLockOperation graphLockOperation = Mockito.mock(IGraphLockOperation.class);
60 private static GroupOperation groupOperation = Mockito.mock(GroupOperation.class);
61 private static GroupDefinition groupDefenition = Mockito.mock(GroupDefinition.class);
62 private static User user = Mockito.mock(User.class);
63 private static String componentId = "vfUniqueId-xxxx";
64 private static String groupUniqueId = "groupUniqueId-xxxx";
66 static GroupBusinessLogic bl = new GroupBusinessLogic();
70 public void setupBeforeMethod() {
71 MockitoAnnotations.initMocks(this);
72 ExternalConfiguration.setAppName("catalog-be");
73 String appConfigDir = "src/test/resources/config/catalog-be";
74 ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
75 ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
76 componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class));
77 when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
79 bl.setComponentsUtils(componentsUtils);
82 public static void setupBeforeClass() {
83 when(graphLockOperation.lockComponent(componentId, ComponentTypeEnum.RESOURCE.getNodeType())).thenReturn(StorageOperationStatus.OK);
84 // when(groupOperation.getGroup(groupUniqueId)).thenReturn(Either.left(groupDefenition));
88 * tests the ValidateMinMaxAndInitialCountPropertyValues() method
90 @SuppressWarnings({ "rawtypes", "unchecked" })
92 public void testValidateMinMaxAndInitialCountPropertyValues(){
94 // Class<GroupBusinessLogic> targetClass = GroupBusinessLogic.class;
95 // String methodName = "validateMinMaxAndInitialCountPropertyValues";
96 // Either<Boolean, ResponseFormat> validationRes;
98 // Map<PropertyNames, String> parentPropertyValues = new EnumMap<>(PropertyNames.class);
99 // parentPropertyValues.put(PropertyNames.MIN_INSTANCES, "20");
100 // parentPropertyValues.put(PropertyNames.MAX_INSTANCES, "100");
101 // parentPropertyValues.put(PropertyNames.INITIAL_COUNT, "40");
103 // Map<PropertyNames, String> parentPropertyValues1 = new EnumMap<>(PropertyNames.class);
104 // parentPropertyValues1.put(PropertyNames.MIN_INSTANCES, "20");
105 // parentPropertyValues1.put(PropertyNames.MAX_INSTANCES, null);
106 // parentPropertyValues1.put(PropertyNames.INITIAL_COUNT, "40");
108 // Map<PropertyNames, String> parentPropertyValues2 = new EnumMap<>(PropertyNames.class);
109 // parentPropertyValues2.put(PropertyNames.MIN_INSTANCES, "20");
110 // parentPropertyValues2.put(PropertyNames.MAX_INSTANCES, "null");
111 // parentPropertyValues2.put(PropertyNames.INITIAL_COUNT, "40");
113 // Map<PropertyNames, String> validNewPropertyValues = new EnumMap<>(PropertyNames.class);
114 // validNewPropertyValues.put(PropertyNames.MIN_INSTANCES, "20");
115 // validNewPropertyValues.put(PropertyNames.MAX_INSTANCES, "100");
116 // validNewPropertyValues.put(PropertyNames.INITIAL_COUNT, "50");
118 // Map<PropertyNames, String> validNewPropertyValues1 = new EnumMap<>(PropertyNames.class);
119 // validNewPropertyValues1.put(PropertyNames.MIN_INSTANCES, "40");
120 // validNewPropertyValues1.put(PropertyNames.MAX_INSTANCES, "90");
121 // validNewPropertyValues1.put(PropertyNames.INITIAL_COUNT, "60");
123 // Map<PropertyNames, String> validNewPropertyValues2 = new EnumMap<>(PropertyNames.class);
124 // validNewPropertyValues2.put(PropertyNames.MIN_INSTANCES, "40");
125 // validNewPropertyValues2.put(PropertyNames.MAX_INSTANCES, null);
126 // validNewPropertyValues2.put(PropertyNames.INITIAL_COUNT, "60");
128 // Map<PropertyNames, String> validNewPropertyValues3 = new EnumMap<>(PropertyNames.class);
129 // validNewPropertyValues3.put(PropertyNames.MIN_INSTANCES, "40");
130 // validNewPropertyValues3.put(PropertyNames.MAX_INSTANCES, "null");
131 // validNewPropertyValues3.put(PropertyNames.INITIAL_COUNT, "60");
133 // Map<PropertyNames, String> validNewPropertyValues4 = new EnumMap<>(PropertyNames.class);
134 // validNewPropertyValues4.put(PropertyNames.MIN_INSTANCES, null);
135 // validNewPropertyValues4.put(PropertyNames.MAX_INSTANCES, null);
136 // validNewPropertyValues4.put(PropertyNames.INITIAL_COUNT, "60");
138 // Map<PropertyNames, String> invalidNewPropertyValues = new EnumMap<>(PropertyNames.class);
139 // invalidNewPropertyValues.put(PropertyNames.MIN_INSTANCES, "20");
140 // invalidNewPropertyValues.put(PropertyNames.MAX_INSTANCES, "10");
141 // invalidNewPropertyValues.put(PropertyNames.INITIAL_COUNT, "5");
143 // Map<PropertyNames, String> invalidNewPropertyValues1 = new EnumMap<>(PropertyNames.class);
144 // invalidNewPropertyValues1.put(PropertyNames.MIN_INSTANCES, "5");
145 // invalidNewPropertyValues1.put(PropertyNames.MAX_INSTANCES, "10");
146 // invalidNewPropertyValues1.put(PropertyNames.INITIAL_COUNT, "20");
148 // Map<PropertyNames, String> invalidNewPropertyValues2 = new EnumMap<>(PropertyNames.class);
149 // invalidNewPropertyValues2.put(PropertyNames.MIN_INSTANCES, "25");
150 // invalidNewPropertyValues2.put(PropertyNames.MAX_INSTANCES, "95");
151 // invalidNewPropertyValues2.put(PropertyNames.INITIAL_COUNT, "100");
153 // Map<PropertyNames, String> invalidNewPropertyValues3 = new EnumMap<>(PropertyNames.class);
154 // invalidNewPropertyValues3.put(PropertyNames.MIN_INSTANCES, null);
155 // invalidNewPropertyValues3.put(PropertyNames.MAX_INSTANCES, "95");
156 // invalidNewPropertyValues3.put(PropertyNames.INITIAL_COUNT, "10");
158 // Map<PropertyNames, String> invalidNewPropertyValues4 = new EnumMap<>(PropertyNames.class);
159 // invalidNewPropertyValues4.put(PropertyNames.MIN_INSTANCES, "30");
160 // invalidNewPropertyValues4.put(PropertyNames.MAX_INSTANCES, "80");
161 // invalidNewPropertyValues4.put(PropertyNames.INITIAL_COUNT, null);
164 // Class[] argClasses = {Map.class, Map.class};
166 // Method method = targetClass.getDeclaredMethod(methodName, argClasses);
167 // method.setAccessible(true);
169 // Object[] argObjects2 = {invalidNewPropertyValues, parentPropertyValues};
170 // validationRes = (Either<Boolean, ResponseFormat>) method.invoke(bl, argObjects2);
171 // assertTrue(validationRes != null);
172 // assertTrue(validationRes.isRight());
173 // assertTrue(validationRes.right().value().getMessageId().equals(ResponseEnum.INVALID_MIN_MAX.getMessageId()));
175 // Object[] argObjects3 = {invalidNewPropertyValues1, parentPropertyValues};
176 // validationRes = (Either<Boolean, ResponseFormat>) method.invoke(bl, argObjects3);
177 // assertTrue(validationRes != null);
178 // assertTrue(validationRes.isRight());
179 // assertTrue(validationRes.right().value().getMessageId().equals(ResponseEnum.INVALID_MIN_MAX.getMessageId()));
181 // Object[] argObjects7 = {invalidNewPropertyValues3, parentPropertyValues};
182 // validationRes = (Either<Boolean, ResponseFormat>) method.invoke(bl, argObjects7);
183 // assertTrue(validationRes != null);
184 // assertTrue(validationRes.isRight());
185 // assertTrue(validationRes.right().value().getMessageId().equals(ResponseEnum.INVALID_MIN_MAX.getMessageId()));
187 // Object[] argObjects = {validNewPropertyValues, parentPropertyValues};
188 // validationRes = (Either<Boolean, ResponseFormat>) method.invoke(bl, argObjects);
189 // assertTrue(validationRes != null);
190 // assertTrue(validationRes.isLeft());
191 // assertTrue(validationRes.left().value());
193 // Object[] argObjects1 = {validNewPropertyValues1, parentPropertyValues};
194 // validationRes = (Either<Boolean, ResponseFormat>) method.invoke(bl, argObjects1);
195 // assertTrue(validationRes != null);
196 // assertTrue(validationRes.isLeft());
197 // assertTrue(validationRes.left().value());
199 // Object[] argObjects5 = {validNewPropertyValues2, parentPropertyValues2};
200 // validationRes = (Either<Boolean, ResponseFormat>) method.invoke(bl, argObjects5);
201 // assertTrue(validationRes != null);
202 // assertTrue(validationRes.isLeft());
203 // assertTrue(validationRes.left().value());
205 // Object[] argObjects6 = {validNewPropertyValues3, parentPropertyValues1};
206 // validationRes = (Either<Boolean, ResponseFormat>) method.invoke(bl, argObjects6);
207 // assertTrue(validationRes != null);
208 // assertTrue(validationRes.isLeft());
209 // assertTrue(validationRes.left().value());
211 // Object[] argObjects9 = {validNewPropertyValues4, parentPropertyValues1};
212 // validationRes = (Either<Boolean, ResponseFormat>) method.invoke(bl, argObjects9);
213 // assertTrue(validationRes != null);
214 // assertTrue(validationRes.isLeft());
215 // assertTrue(validationRes.left().value());
217 // Object[] argObjects4 = {invalidNewPropertyValues2, parentPropertyValues};
218 // validationRes = (Either<Boolean, ResponseFormat>) method.invoke(bl, argObjects4);
219 // assertTrue(validationRes != null);
220 // assertTrue(validationRes.isRight());
221 // assertTrue(validationRes.right().value().getMessageId().equals(ResponseEnum.INVALID_INITIAL_COUNT.getMessageId()));
223 // Object[] argObjects8 = {invalidNewPropertyValues4, parentPropertyValues};
224 // validationRes = (Either<Boolean, ResponseFormat>) method.invoke(bl, argObjects8);
225 // assertTrue(validationRes != null);
226 // assertTrue(validationRes.isRight());
227 // assertTrue(validationRes.right().value().getMessageId().equals(ResponseEnum.INVALID_INITIAL_COUNT.getMessageId()));
229 // catch (Exception e) {
230 // e.printStackTrace();