1 package org.onap.aai.sparky.editattributes;
3 * ============LICENSE_START===================================================
4 * SPARKY (AAI UI service)
5 * ============================================================================
6 * Copyright © 2017 AT&T Intellectual Property.
7 * Copyright © 2017 Amdocs
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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=====================================================
23 * ECOMP and OpenECOMP are trademarks
24 * and service marks of AT&T Intellectual Property.
27 package org.openecomp.sparky.editattributes;
29 import static org.junit.Assert.assertEquals;
31 import java.util.HashMap;
34 import javax.ws.rs.core.Response.Status;
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;
48 * The Class AttributeUpdaterTest.
50 public class AttributeUpdaterTest {
55 * @throws Exception the exception
58 public void setUp() throws Exception {}
65 public void testUpdateObjectAttribute() throws Exception {
67 OxmEntityDescriptor desc = new OxmEntityDescriptor();
68 desc.addPrimaryKeyName("hostname");
69 desc.setEntityName("pserver");
71 OxmEntityLookup entityLookup = OxmEntityLookup.getInstance();
72 entityLookup.addEntityDescriptor("pserver", desc);
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());
85 // This needs the OXM file in place to work.
87 * Test get edit object from uri.
89 * @throws Exception the exception
92 /*public void testGetEditObjectFromUri() throws Exception {
94 OxmModelLoader loader = new OxmModelLoader();
95 loader.setLatestVersionNum(11);
97 OxmEntityDescriptor desc = new OxmEntityDescriptor();
98 desc.addPrimaryKeyName("hostname");
99 desc.setEntityName("pserver");
101 OxmEntityLookup entityLookup = OxmEntityLookup.getInstance();
102 entityLookup.addEntityDescriptor("pserver", desc);
105 DynamicType mockType = Mockito.mock(DynamicType.class);
106 Class<? extends DynamicEntity> mockDynamicEntity = Mockito.mock(DynamicEntity.class);
108 Mockito.when(mockType.getJavaClass()).thenReturn(mockDynamicEntity);
113 HashMap<String, DynamicType> typeLookup = new HashMap<String,DynamicType>();
114 typeLookup.put("pserver", mockType);
116 entityLookup.setEntityTypeLookup(typeLookup);
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());
130 * Test get relative uri.
132 * @throws Exception the exception
136 public void testGetRelativeUri() throws Exception {
138 OxmEntityDescriptor desc = new OxmEntityDescriptor();
139 desc.addPrimaryKeyName("hostname");
140 desc.setEntityName("pserver");
142 OxmEntityLookup entityLookup = OxmEntityLookup.getInstance();
143 entityLookup.addEntityDescriptor("pserver", desc);
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);
153 result = updater.getRelativeUri("/v8/cloud-infrastructure/pservers/pserver/mtznjtax101");
154 assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);
156 result = updater.getRelativeUri("aai/v88/cloud-infrastructure/pservers/pserver/mtznjtax101");
157 assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);
159 result = updater.getRelativeUri("/cloud-infrastructure/pservers/pserver/mtznjtax101");
160 assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);