Convert Sparky to Spring-Boot
[aai/sparky-be.git] / sparkybe-onap-service / src / test / java / org / onap / aai / sparky / editattributes / AttributeUpdaterTest.java
1 package org.onap.aai.sparky.editattributes;
2 /**
3  * ============LICENSE_START===================================================
4  * SPARKY (AAI UI service)
5  * ============================================================================
6  * Copyright © 2017 AT&T Intellectual Property.
7  * Copyright © 2017 Amdocs
8  * All rights reserved.
9  * ============================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=====================================================
22  *
23  * ECOMP and OpenECOMP are trademarks
24  * and service marks of AT&T Intellectual Property.
25  */
26 /*
27 package org.openecomp.sparky.editattributes;
28
29 import static org.junit.Assert.assertEquals;
30
31 import java.util.HashMap;
32 import java.util.Map;
33
34 import javax.ws.rs.core.Response.Status;
35
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.onap.aai.restclient.client.OperationResult;
39 import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
40 import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
41 import org.onap.aai.sparky.config.oxm.OxmModelLoader;
42 import org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig;
43 import org.onap.aai.sparky.editattributes.AttributeUpdater;
44 import org.openecomp.sparky.dal.aai.config.ActiveInventoryConfigUtil;
45
46
47 /**
48  * The Class AttributeUpdaterTest.
49  *
50 public class AttributeUpdaterTest {
51
52   /**
53    * Sets the up.
54    *
55    * @throws Exception the exception
56    *
57   @Before
58   public void setUp() throws Exception {}
59
60   /**
61    * @throws Exception 
62    */
63   /*
64   @Test
65   public void testUpdateObjectAttribute() throws Exception {
66     
67     OxmEntityDescriptor desc = new OxmEntityDescriptor();
68     desc.addPrimaryKeyName("hostname");
69     desc.setEntityName("pserver");
70     
71     OxmEntityLookup entityLookup = OxmEntityLookup.getInstance();
72     entityLookup.addEntityDescriptor("pserver", desc);
73     
74     AttributeUpdater updater = new AttributeUpdater(new OxmModelLoader(), entityLookup,
75         new ActiveInventoryConfig(ActiveInventoryConfigUtil.getValidTestProperties()));
76     Map<String, Object> attributes = new HashMap<>();
77     attributes.put("prov-status", "PREPROV");
78     attributes.put("in-maint", "true");
79     OperationResult result = updater.updateObjectAttribute(
80         "cloud-infrastructure/pservers/pserver/something", attributes, "someid");
81     assertEquals(Status.FORBIDDEN.getStatusCode(), result.getResultCode());
82   }
83   */
84
85   // This needs the OXM file in place to work.
86   /**
87    * Test get edit object from uri.
88    *
89    * @throws Exception the exception
90    */
91   //@Test
92   /*public void testGetEditObjectFromUri() throws Exception {
93     
94     OxmModelLoader loader = new OxmModelLoader();
95     loader.setLatestVersionNum(11);
96     
97     OxmEntityDescriptor desc = new OxmEntityDescriptor();
98     desc.addPrimaryKeyName("hostname");
99     desc.setEntityName("pserver");
100     
101     OxmEntityLookup entityLookup = OxmEntityLookup.getInstance();
102     entityLookup.addEntityDescriptor("pserver", desc);
103     
104
105     DynamicType mockType = Mockito.mock(DynamicType.class);
106     Class<? extends DynamicEntity> mockDynamicEntity = Mockito.mock(DynamicEntity.class);
107
108     Mockito.when(mockType.getJavaClass()).thenReturn(mockDynamicEntity);
109
110     
111     
112     
113     HashMap<String, DynamicType> typeLookup = new HashMap<String,DynamicType>();
114     typeLookup.put("pserver", mockType);
115
116     entityLookup.setEntityTypeLookup(typeLookup);
117     
118     
119     AttributeUpdater updater = new AttributeUpdater(new OxmModelLoader(), entityLookup, 
120         new ActiveInventoryConfig(ActiveInventoryConfigUtil.getValidTestProperties()));
121     AaiEditObject result =
122         updater.getEditObjectFromUri("cloud-infrastructure/pservers/pserver/mtznjtax101");
123     assertEquals("Pserver", result.getObjectType());
124     assertEquals("pserver", result.getRootElement());
125     assertEquals("hostname", result.getKeyName());
126     assertEquals("mtznjtax101", result.getKeyValue());
127   }*/
128
129   /**
130    * Test get relative uri.
131    *
132    * @throws Exception the exception
133    */
134   /*
135   @Test
136   public void testGetRelativeUri() throws Exception {
137     
138     OxmEntityDescriptor desc = new OxmEntityDescriptor();
139     desc.addPrimaryKeyName("hostname");
140     desc.setEntityName("pserver");
141     
142     OxmEntityLookup entityLookup = OxmEntityLookup.getInstance();
143     entityLookup.addEntityDescriptor("pserver", desc);
144     
145     AttributeUpdater updater = new AttributeUpdater(new OxmModelLoader(), entityLookup,
146         new ActiveInventoryConfig(ActiveInventoryConfigUtil.getValidTestProperties()));
147     // Test entity uri without "/aai/version/"
148     String result = updater.getRelativeUri("cloud-infrastructure/pservers/pserver/mtznjtax101");
149     assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);
150     result = updater.getRelativeUri("/aai/v8/cloud-infrastructure/pservers/pserver/mtznjtax101");
151     assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);
152
153     result = updater.getRelativeUri("/v8/cloud-infrastructure/pservers/pserver/mtznjtax101");
154     assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);
155
156     result = updater.getRelativeUri("aai/v88/cloud-infrastructure/pservers/pserver/mtznjtax101");
157     assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);
158
159     result = updater.getRelativeUri("/cloud-infrastructure/pservers/pserver/mtznjtax101");
160     assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);
161   }
162   
163 }
164 */