Added oparent to sdc main
[sdc.git] / openecomp-be / api / openecomp-sdc-rest-webapp / togglz-rest / togglz-rest-services / src / test / java / org / openecomp / TogglzFeatureRestTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp;
22
23 import com.google.common.collect.Sets;
24 import org.junit.Test;
25 import org.openecomp.sdc.common.togglz.ToggleableFeature;
26 import org.openecomp.sdcrests.togglz.rest.TogglzFeatures;
27 import org.openecomp.sdcrests.togglz.rest.mapping.MapToggleableFeatureToDto;
28 import org.openecomp.sdcrests.togglz.rest.services.TogglzFeaturesImpl;
29 import org.openecomp.sdcrests.togglz.types.FeatureDto;
30 import org.openecomp.sdcrests.togglz.types.FeatureSetDto;
31
32 import javax.ws.rs.core.Response;
33 import java.util.Arrays;
34 import java.util.Collection;
35 import java.util.Collections;
36 import java.util.Set;
37 import java.util.stream.Collectors;
38
39 import static org.junit.Assert.*;
40 import static org.mockito.Mockito.mock;
41 import static org.mockito.Mockito.when;
42
43 public class TogglzFeatureRestTest {
44
45     @Test
46     public void shouldConvertDataProperly() {
47         ToggleableFeature tf = mock(ToggleableFeature.class);
48         final String TF_NAME = "tf";
49         final boolean ACTIVE = true;
50         when(tf.name()).thenReturn(TF_NAME);
51         when(tf.isActive()).thenReturn(ACTIVE);
52         MapToggleableFeatureToDto mapToggleableFeatureToDto = new MapToggleableFeatureToDto();
53         FeatureSetDto target = new FeatureSetDto();
54         Collection<ToggleableFeature> source = Collections.singletonList(tf);
55         mapToggleableFeatureToDto.doMapping(source, target);
56         assertEquals(source.size(), target.getFeatures().size());
57         FeatureDto result = target.getFeatures().iterator().next();
58         assertEquals(TF_NAME, result.getName());
59         assertEquals(ACTIVE, result.isActive());
60
61     }
62
63     @Test
64     public void shouldGetCurrentTogglzValues() {
65         TogglzFeatures togglzFeature = new TogglzFeaturesImpl();
66         Response response = togglzFeature.getFeatures();
67         assertNotNull(response);
68         Object entity = response.getEntity();
69         assertEquals(entity.getClass(), FeatureSetDto.class);
70         Set<FeatureDto> features = ((FeatureSetDto) entity).getFeatures();
71         assertEquals(features.size(), ToggleableFeature.values().length);
72         Set<String> names = Arrays.stream(ToggleableFeature.values()).map(Enum::name).collect(Collectors.toSet());
73         Set<String> dtoNames = features.stream().map(FeatureDto::getName).collect(Collectors.toSet());
74         assertTrue(Sets.symmetricDifference(names, dtoNames).isEmpty());
75     }
76 }