2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 package org.onap.aai.sparky.editattributes;
28 import static org.junit.Assert.assertEquals;
30 import java.util.HashMap;
33 import javax.ws.rs.core.Response.Status;
35 import org.eclipse.persistence.dynamic.DynamicType;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.mockito.Mockito;
39 import org.onap.aai.restclient.client.OperationResult;
40 import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
41 import org.onap.aai.sparky.config.oxm.OxmEntityLookup;
42 import org.onap.aai.sparky.config.oxm.OxmModelLoader;
43 import org.onap.aai.sparky.dal.ActiveInventoryAdapter;
44 import org.onap.aai.sparky.editattributes.AttributeUpdater;
45 import org.onap.aai.sparky.editattributes.AttributeUpdater.AaiEditObject;
50 * The Class AttributeUpdaterTest.
52 public class AttributeUpdaterTest {
54 private ActiveInventoryAdapter aaiAdapter;
59 * @throws Exception the exception
62 public void setUp() throws Exception {
64 aaiAdapter = Mockito.mock(ActiveInventoryAdapter.class);
72 public void testUpdateObjectAttribute() throws Exception {
74 OxmEntityDescriptor desc = new OxmEntityDescriptor();
75 desc.addPrimaryKeyName("hostname");
76 desc.setEntityName("pserver");
78 OxmEntityLookup entityLookup = new OxmEntityLookup();
79 entityLookup.addEntityDescriptor("pserver", desc);
81 AttributeUpdater updater = new AttributeUpdater(new OxmModelLoader(), entityLookup, aaiAdapter);
82 Map<String, Object> attributes = new HashMap<>();
83 attributes.put("prov-status", "PREPROV");
84 attributes.put("in-maint", "true");
85 OperationResult result = updater.updateObjectAttribute(
86 "cloud-infrastructure/pservers/pserver/something", attributes, "someid");
87 assertEquals(Status.FORBIDDEN.getStatusCode(), result.getResultCode());
91 // This needs the OXM file in place to work.
93 * Test get edit object from uri.
95 * @throws Exception the exception
97 @Test(expected = NullPointerException.class)
98 public void testGetEditObjectFromUri() throws Exception {
100 OxmModelLoader loader = new OxmModelLoader();
101 loader.setLatestVersionNum(11);
103 OxmEntityDescriptor desc = new OxmEntityDescriptor();
104 desc.addPrimaryKeyName("hostname");
105 desc.setEntityName("pserver");
107 OxmEntityLookup entityLookup = new OxmEntityLookup();
108 entityLookup.addEntityDescriptor("pserver", desc);
111 // DynamicType mockType = Mockito.mock(DynamicType.class);
112 // Class<? extends DynamicEntity> mockDynamicEntity = Mockito.mock(DynamicEntity.class);
114 // Mockito.when(mockType.getJavaClass()).thenReturn(mockDynamicEntity);
118 HashMap<String, DynamicType> typeLookup = new HashMap<String, DynamicType>();
119 // typeLookup.put("pserver", mockType);
121 entityLookup.setEntityTypeLookup(typeLookup);
124 AttributeUpdater updater = new AttributeUpdater(new OxmModelLoader(), entityLookup, aaiAdapter);
125 AaiEditObject result = updater.getEditObjectFromUri(null);
126 assertEquals("Pserver", result.getObjectType());
127 assertEquals("pserver", result.getRootElement());
128 assertEquals("hostname", result.getKeyName());
129 assertEquals("mtznjtax101", result.getKeyValue());
133 * Test get relative uri.
135 * @throws Exception the exception
139 public void testGetRelativeUri() throws Exception {
141 OxmEntityDescriptor desc = new OxmEntityDescriptor();
142 desc.addPrimaryKeyName("hostname");
143 desc.setEntityName("pserver");
145 OxmEntityLookup entityLookup = new OxmEntityLookup();
146 entityLookup.addEntityDescriptor("pserver", desc);
148 AttributeUpdater updater = new AttributeUpdater(new OxmModelLoader(), entityLookup, aaiAdapter);
149 // Test entity uri without "/aai/version/"
150 String result = updater.getRelativeUri("cloud-infrastructure/pservers/pserver/mtznjtax101");
151 assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);
152 result = updater.getRelativeUri("/aai/v8/cloud-infrastructure/pservers/pserver/mtznjtax101");
153 assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);
155 result = updater.getRelativeUri("/v8/cloud-infrastructure/pservers/pserver/mtznjtax101");
156 assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);
158 result = updater.getRelativeUri("aai/v88/cloud-infrastructure/pservers/pserver/mtznjtax101");
159 assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);
161 result = updater.getRelativeUri("/cloud-infrastructure/pservers/pserver/mtznjtax101");
162 assertEquals("/cloud-infrastructure/pservers/pserver/mtznjtax101", result);