1 package org.onap.aai.sparky.editattributes;
3 * ============LICENSE_START=================================================== SPARKY (AAI UI
4 * service) ============================================================================ Copyright ©
5 * 2017 AT&T Intellectual Property. Copyright © 2017 Amdocs All rights reserved.
6 * ============================================================================ Licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
15 * the License. ============LICENSE_END=====================================================
17 * ECOMP and OpenECOMP are trademarks and service marks of AT&T Intellectual Property.
20 * package org.openecomp.sparky.editattributes;
22 * import static org.junit.Assert.assertEquals;
24 * import java.util.HashMap; import java.util.Map;
26 * import javax.ws.rs.core.Response.Status;
28 * import org.junit.Before; import org.junit.Test; import
29 * org.onap.aai.restclient.client.OperationResult; import
30 * org.onap.aai.sparky.config.oxm.OxmEntityDescriptor; import
31 * org.onap.aai.sparky.config.oxm.OxmEntityLookup; import
32 * org.onap.aai.sparky.config.oxm.OxmModelLoader; import
33 * org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig; import
34 * org.onap.aai.sparky.editattributes.AttributeUpdater; import
35 * org.openecomp.sparky.dal.aai.config.ActiveInventoryConfigUtil;
38 * /** The Class AttributeUpdaterTest.
40 * public class AttributeUpdaterTest {
44 * @throws Exception the exception
46 * @Before public void setUp() throws Exception {}
54 * @Test public void testUpdateObjectAttribute() throws Exception {
56 * OxmEntityDescriptor desc = new OxmEntityDescriptor(); desc.addPrimaryKeyName("hostname");
57 * desc.setEntityName("pserver");
59 * OxmEntityLookup entityLookup = OxmEntityLookup.getInstance();
60 * entityLookup.addEntityDescriptor("pserver", desc);
62 * AttributeUpdater updater = new AttributeUpdater(new OxmModelLoader(), entityLookup, new
63 * ActiveInventoryConfig(ActiveInventoryConfigUtil.getValidTestProperties())); Map<String, Object>
64 * attributes = new HashMap<>(); attributes.put("prov-status", "PREPROV");
65 * attributes.put("in-maint", "true"); OperationResult result = updater.updateObjectAttribute(
66 * "cloud-infrastructure/pservers/pserver/something", attributes, "someid");
67 * assertEquals(Status.FORBIDDEN.getStatusCode(), result.getResultCode()); }
70 // This needs the OXM file in place to work.
72 * Test get edit object from uri.
74 * @throws Exception the exception
78 * public void testGetEditObjectFromUri() throws Exception {
80 * OxmModelLoader loader = new OxmModelLoader(); loader.setLatestVersionNum(11);
82 * OxmEntityDescriptor desc = new OxmEntityDescriptor(); desc.addPrimaryKeyName("hostname");
83 * desc.setEntityName("pserver");
85 * OxmEntityLookup entityLookup = OxmEntityLookup.getInstance();
86 * entityLookup.addEntityDescriptor("pserver", desc);
89 * DynamicType mockType = Mockito.mock(DynamicType.class); Class<? extends DynamicEntity>
90 * mockDynamicEntity = Mockito.mock(DynamicEntity.class);
92 * Mockito.when(mockType.getJavaClass()).thenReturn(mockDynamicEntity);
97 * HashMap<String, DynamicType> typeLookup = new HashMap<String,DynamicType>();
98 * typeLookup.put("pserver", mockType);
100 * entityLookup.setEntityTypeLookup(typeLookup);
103 * AttributeUpdater updater = new AttributeUpdater(new OxmModelLoader(), entityLookup, new
104 * ActiveInventoryConfig(ActiveInventoryConfigUtil.getValidTestProperties())); AaiEditObject result
105 * = updater.getEditObjectFromUri("cloud-infrastructure/pservers/pserver/mtznjtax101");
106 * assertEquals("Pserver", result.getObjectType()); assertEquals("pserver",
107 * result.getRootElement()); assertEquals("hostname", result.getKeyName());
108 * assertEquals("mtznjtax101", result.getKeyValue()); }
112 * Test get relative uri.
114 * @throws Exception the exception
117 * @Test public void testGetRelativeUri() throws Exception {
119 * OxmEntityDescriptor desc = new OxmEntityDescriptor(); desc.addPrimaryKeyName("hostname");
120 * desc.setEntityName("pserver");
122 * OxmEntityLookup entityLookup = OxmEntityLookup.getInstance();
123 * entityLookup.addEntityDescriptor("pserver", desc);
125 * AttributeUpdater updater = new AttributeUpdater(new OxmModelLoader(), entityLookup, new
126 * ActiveInventoryConfig(ActiveInventoryConfigUtil.getValidTestProperties())); // Test entity uri
127 * without "/aai/version/" String result =
128 * updater.getRelativeUri("cloud-infrastructure/pservers/pserver/mtznjtax101");
129 * assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result); result =
130 * updater.getRelativeUri("/aai/v8/cloud-infrastructure/pservers/pserver/mtznjtax101");
131 * assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);
133 * result = updater.getRelativeUri("/v8/cloud-infrastructure/pservers/pserver/mtznjtax101");
134 * assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);
136 * result = updater.getRelativeUri("aai/v88/cloud-infrastructure/pservers/pserver/mtznjtax101");
137 * assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);
139 * result = updater.getRelativeUri("/cloud-infrastructure/pservers/pserver/mtznjtax101");
140 * assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result); }