You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2016/02/02 13:40:52 UTC
[07/11] ambari git commit: AMBARI-14869: Rename AdminSetting API to
Setting (Ajit Kumar via smnaha)
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/ambari-server/src/test/java/org/apache/ambari/server/api/services/SettingServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/SettingServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/SettingServiceTest.java
new file mode 100644
index 0000000..598e420
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/SettingServiceTest.java
@@ -0,0 +1,101 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.api.services;
+
+import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.api.services.parsers.RequestBodyParser;
+import org.apache.ambari.server.api.services.serializers.ResultSerializer;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.UriInfo;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Unit test for {@link SettingService}
+ */
+public class SettingServiceTest extends BaseServiceTest {
+ @Override
+ public List<ServiceTestInvocation> getTestInvocations() throws Exception {
+ List<ServiceTestInvocation> listInvocations = new ArrayList<>();
+
+ //getSetting
+ SettingService settingService = new TestSettingService("settingName");
+ Method m = settingService.getClass().getMethod("getSetting", String.class, HttpHeaders.class, UriInfo.class, String.class);
+ Object[] args = new Object[] {null, getHttpHeaders(), getUriInfo(), "settingName"};
+ listInvocations.add(new ServiceTestInvocation(Request.Type.GET, settingService, m, args, null));
+
+ //getSettings
+ settingService = new TestSettingService(null);
+ m = settingService.getClass().getMethod("getSettings", String.class, HttpHeaders.class, UriInfo.class);
+ args = new Object[] {null, getHttpHeaders(), getUriInfo()};
+ listInvocations.add(new ServiceTestInvocation(Request.Type.GET, settingService, m, args, null));
+
+ //createSetting
+ settingService = new TestSettingService(null);
+ m = settingService.getClass().getMethod("createSetting", String.class, HttpHeaders.class, UriInfo.class);
+ args = new Object[] {"body", getHttpHeaders(), getUriInfo()};
+ listInvocations.add(new ServiceTestInvocation(Request.Type.POST, settingService, m, args, "body"));
+
+ //updateSetting
+ settingService = new TestSettingService("settingName");
+ m = settingService.getClass().getMethod("updateSetting", String.class, HttpHeaders.class, UriInfo.class, String.class);
+ args = new Object[] {"body", getHttpHeaders(), getUriInfo(), "settingName"};
+ listInvocations.add(new ServiceTestInvocation(Request.Type.PUT, settingService, m, args, "body"));
+
+ //deleteSetting
+ settingService = new TestSettingService("settingName");
+ m = settingService.getClass().getMethod("deleteSetting", HttpHeaders.class, UriInfo.class, String.class);
+ args = new Object[] {getHttpHeaders(), getUriInfo(), "settingName"};
+ listInvocations.add(new ServiceTestInvocation(Request.Type.DELETE, settingService, m, args, null));
+
+ return listInvocations;
+ }
+
+ private class TestSettingService extends SettingService {
+ private String settingName;
+
+ private TestSettingService(String settingName) {
+ this.settingName = settingName;
+ }
+
+ @Override
+ ResourceInstance createSettingResource(String settingName) {
+ assertEquals(this.settingName, settingName);
+ return getTestResource();
+ }
+
+ @Override
+ RequestFactory getRequestFactory() {
+ return getTestRequestFactory();
+ }
+
+ @Override
+ protected RequestBodyParser getBodyParser() {
+ return getTestBodyParser();
+ }
+
+ @Override
+ protected ResultSerializer getResultSerializer() {
+ return getTestResultSerializer();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AdminSettingResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AdminSettingResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AdminSettingResourceProviderTest.java
deleted file mode 100644
index e95449c..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AdminSettingResourceProviderTest.java
+++ /dev/null
@@ -1,356 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.server.controller.internal;
-
-import com.google.common.collect.Lists;
-import org.apache.ambari.server.DuplicateResourceException;
-import org.apache.ambari.server.controller.spi.Predicate;
-import org.apache.ambari.server.controller.spi.Request;
-import org.apache.ambari.server.controller.spi.RequestStatus;
-import org.apache.ambari.server.controller.spi.Resource;
-import org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException;
-import org.apache.ambari.server.controller.utilities.PredicateBuilder;
-import org.apache.ambari.server.controller.utilities.PropertyHelper;
-import org.apache.ambari.server.orm.dao.AdminSettingDAO;
-import org.apache.ambari.server.orm.entities.AdminSettingEntity;
-import org.apache.ambari.server.security.TestAuthenticationFactory;
-import org.apache.ambari.server.security.authorization.AuthorizationException;
-import org.apache.ambari.server.security.authorization.AuthorizationHelper;
-import org.apache.commons.lang.RandomStringUtils;
-import org.easymock.Capture;
-import org.easymock.IMocksControl;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.springframework.security.core.context.SecurityContextHolder;
-
-import java.lang.reflect.Field;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import static org.apache.ambari.server.controller.internal.AdminSettingResourceProvider.ADMINSETTING_NAME_PROPERTY_ID;
-import static org.apache.ambari.server.controller.internal.AdminSettingResourceProvider.ADMINSETTING_SETTING_TYPE_PROPERTY_ID;
-import static org.apache.ambari.server.controller.internal.AdminSettingResourceProvider.ADMINSETTING_CONTENT_PROPERTY_ID;
-import static org.apache.ambari.server.controller.internal.AdminSettingResourceProvider.ADMINSETTING_UPDATED_BY_PROPERTY_ID;
-import static org.apache.ambari.server.controller.internal.AdminSettingResourceProvider.ADMINSETTING_UPDATE_TIMESTAMP_PROPERTY_ID;
-import static org.easymock.EasyMock.capture;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.createControl;
-
-import static org.junit.Assert.assertEquals;
-
-public class AdminSettingResourceProviderTest {
- IMocksControl mockControl;
- AdminSettingDAO dao;
- AdminSettingResourceProvider resourceProvider;
-
-
- @Before
- public void setUp() throws Exception {
- mockControl = createControl();
- dao = mockControl.createMock(AdminSettingDAO.class);
- resourceProvider = new AdminSettingResourceProvider();
- setPrivateField(resourceProvider, "dao", dao);
- }
-
- @After
- public void tearDown() {
- mockControl.verify();
- SecurityContextHolder.getContext().setAuthentication(null);
- mockControl.reset();
- }
-
- @Test(expected = AuthorizationException.class)
- public void testGetResources_instance_noAuth() throws Exception {
- getResources_instance(newEntity("motd"), readRequest());
- }
-
- @Test
- public void testGetResources_instance_clusterUser() throws Exception {
- setupAuthenticationForClusterUser();
- String name = "motd";
- AdminSettingEntity entity = newEntity(name);
-
- Set<Resource> response = getResources_instance(entity, readRequest());
- assertEquals(1, response.size());
- Resource resource = response.iterator().next();
- assertEqualsEntityAndResource(entity, resource);
- }
-
- @Test
- public void testGetResources_instance_admin() throws Exception {
- setupAuthenticationForAdmin();
- AdminSettingEntity entity = newEntity("motd");
- Set<Resource> response = getResources_instance(entity, readRequest());
- assertEquals(1, response.size());
- Resource resource = response.iterator().next();
- assertEqualsEntityAndResource(entity, resource);
- }
-
- @Test(expected = AuthorizationException.class)
- public void testGetResources_collection_noAuth() throws Exception {
- mockControl.replay();
- Request request = PropertyHelper.getReadRequest(
- ADMINSETTING_NAME_PROPERTY_ID,
- ADMINSETTING_CONTENT_PROPERTY_ID,
- ADMINSETTING_SETTING_TYPE_PROPERTY_ID,
- ADMINSETTING_UPDATED_BY_PROPERTY_ID,
- ADMINSETTING_UPDATE_TIMESTAMP_PROPERTY_ID);
- resourceProvider.getResources(request, null);
- }
-
- @Test
- public void testGetResources_collection_clusterUser() throws Exception {
- setupAuthenticationForClusterUser();
-
- AdminSettingEntity entity1 = newEntity("motd");
- AdminSettingEntity entity2 = newEntity("ldap");
- Request request = PropertyHelper.getReadRequest(
- ADMINSETTING_NAME_PROPERTY_ID,
- ADMINSETTING_CONTENT_PROPERTY_ID,
- ADMINSETTING_SETTING_TYPE_PROPERTY_ID,
- ADMINSETTING_UPDATED_BY_PROPERTY_ID,
- ADMINSETTING_UPDATE_TIMESTAMP_PROPERTY_ID);
-
- expect(dao.findAll()).andReturn(Lists.newArrayList(entity1, entity2));
- mockControl.replay();
-
- Set<Resource> response = resourceProvider.getResources(request, null);
- assertEquals(2, response.size());
- Map<Object, Resource> resourceMap = new HashMap<>();
- Iterator<Resource> resourceIterator = response.iterator();
- Resource nextResource = resourceIterator.next();
- resourceMap.put(nextResource.getPropertyValue(ADMINSETTING_NAME_PROPERTY_ID), nextResource);
- nextResource = resourceIterator.next();
- resourceMap.put(nextResource.getPropertyValue(ADMINSETTING_NAME_PROPERTY_ID), nextResource);
- assertEqualsEntityAndResource(entity1, resourceMap.get(entity1.getName()));
- assertEqualsEntityAndResource(entity2, resourceMap.get(entity2.getName()));
- }
-
- @Test
- public void testGetResources_collection_admin() throws Exception {
- setupAuthenticationForAdmin();
-
- AdminSettingEntity entity1 = newEntity("motd");
- AdminSettingEntity entity2 = newEntity("ldap");
- Request request = PropertyHelper.getReadRequest(
- ADMINSETTING_NAME_PROPERTY_ID,
- ADMINSETTING_CONTENT_PROPERTY_ID,
- ADMINSETTING_SETTING_TYPE_PROPERTY_ID,
- ADMINSETTING_UPDATED_BY_PROPERTY_ID,
- ADMINSETTING_UPDATE_TIMESTAMP_PROPERTY_ID);
- expect(dao.findAll()).andReturn(Lists.newArrayList(entity1, entity2));
- mockControl.replay();
-
- Set<Resource> response = resourceProvider.getResources(request, null);
- assertEquals(2, response.size());
- Map<Object, Resource> resourceMap = new HashMap<>();
- Iterator<Resource> resourceIterator = response.iterator();
- Resource nextResource = resourceIterator.next();
- resourceMap.put(nextResource.getPropertyValue(ADMINSETTING_NAME_PROPERTY_ID), nextResource);
- nextResource = resourceIterator.next();
- resourceMap.put(nextResource.getPropertyValue(ADMINSETTING_NAME_PROPERTY_ID), nextResource);
- assertEqualsEntityAndResource(entity1, resourceMap.get(entity1.getName()));
- assertEqualsEntityAndResource(entity2, resourceMap.get(entity2.getName()));
- }
-
- @Test(expected = AuthorizationException.class)
- public void testCreateResource_noAuth() throws Exception {
- mockControl.replay();
- resourceProvider.createResources(createRequest(newEntity("moted")));
- }
-
- @Test(expected = AuthorizationException.class)
- public void testCreateResource_clusterUser() throws Exception {
- setupAuthenticationForClusterUser();
- mockControl.replay();
- resourceProvider.createResources(createRequest(newEntity("motd")));
- }
-
- @Test
- public void testCreateResource_admin() throws Exception {
- setupAuthenticationForAdmin();
- AdminSettingEntity entity = newEntity("motd");
- Capture<AdminSettingEntity> entityCapture = Capture.newInstance();
- Request request = createRequest(entity);
-
- expect(dao.findByName(entity.getName())).andReturn(null);
- dao.create(capture(entityCapture));
- mockControl.replay();
-
- RequestStatus response = resourceProvider.createResources(request);
- assertEquals(RequestStatus.Status.Complete, response.getStatus());
- Set<Resource> associatedResources = response.getAssociatedResources();
- assertEquals(1, associatedResources.size());
- AdminSettingEntity capturedEntity = entityCapture.getValue();
- assertEquals(entity.getName(), capturedEntity.getName());
- assertEquals(entity.getContent(), capturedEntity.getContent());
- assertEquals(entity.getSettingType(), capturedEntity.getSettingType());
- assertEquals(AuthorizationHelper.getAuthenticatedName(), capturedEntity.getUpdatedBy());
- }
-
- @Test(expected = ResourceAlreadyExistsException.class)
- public void testCreateDuplicateResource() throws Exception {
- setupAuthenticationForAdmin();
- AdminSettingEntity entity = newEntity("motd");
- Request request = createRequest(entity);
-
- expect(dao.findByName(entity.getName())).andReturn(entity);
- mockControl.replay();
- resourceProvider.createResources(request);
- }
-
- @Test(expected = AuthorizationException.class)
- public void testUpdateResources_noAuth() throws Exception {
- mockControl.replay();
- resourceProvider.updateResources(updateRequest(newEntity("motd")), null);
- }
-
- @Test(expected = AuthorizationException.class)
- public void testUpdateResources_clusterUser() throws Exception {
- setupAuthenticationForClusterUser();
- mockControl.replay();
- resourceProvider.updateResources(updateRequest(newEntity("motd")), null);
- }
-
- @Test
- public void testUpdateResources_admin() throws Exception {
- setupAuthenticationForAdmin();
- String name = "motd";
- AdminSettingEntity oldEntity = newEntity(name);
- AdminSettingEntity updatedEntity = oldEntity.clone();
- updatedEntity.setContent("{text}");
- updatedEntity.setSettingType("new-type");
-
- PredicateBuilder pb = new PredicateBuilder();
- Predicate predicate = pb.begin().property(ADMINSETTING_NAME_PROPERTY_ID).equals(name).end().toPredicate();
- Capture<AdminSettingEntity> capture = Capture.newInstance();
-
- expect(dao.findByName(name)).andReturn(oldEntity);
- expect(dao.merge(capture(capture))).andReturn(updatedEntity);
- mockControl.replay();
-
- RequestStatus response = resourceProvider.updateResources(updateRequest(updatedEntity), predicate);
- AdminSettingEntity capturedEntity = capture.getValue();
- assertEquals(RequestStatus.Status.Complete, response.getStatus());
- assertEquals(updatedEntity.getId(), capturedEntity.getId());
- assertEquals(updatedEntity.getName(), capturedEntity.getName());
- assertEquals(updatedEntity.getSettingType(), capturedEntity.getSettingType());
- assertEquals(updatedEntity.getContent(), capturedEntity.getContent());
- assertEquals(AuthorizationHelper.getAuthenticatedName(), capturedEntity.getUpdatedBy());
- }
-
- @Test(expected = AuthorizationException.class)
- public void testDeleteResources_noAuth() throws Exception {
- mockControl.replay();
- resourceProvider.deleteResources(null);
- }
-
-
- @Test(expected = AuthorizationException.class)
- public void testDeleteResources_clusterUser() throws Exception {
- setupAuthenticationForClusterUser();
- mockControl.replay();
- resourceProvider.deleteResources(null);
- }
-
- @Test
- public void testDeleteResources() throws Exception {
- setupAuthenticationForAdmin();
-
- String name = "motd";
- PredicateBuilder pb = new PredicateBuilder();
- Predicate predicate = pb.begin().property(ADMINSETTING_NAME_PROPERTY_ID).equals(name).end().toPredicate();
- dao.removeByName(name);
- mockControl.replay();
- resourceProvider.deleteResources(predicate);
- }
-
- private Set<Resource> getResources_instance(AdminSettingEntity entity, Request request) throws Exception {
- String name = entity.getName();
- PredicateBuilder pb = new PredicateBuilder();
- Predicate predicate = pb.begin().property(ADMINSETTING_NAME_PROPERTY_ID).equals(name).end().toPredicate();
-
- expect(dao.findByName(name)).andReturn(entity).anyTimes();
- mockControl.replay();
- return resourceProvider.getResources(request, predicate);
- }
-
-
- private Request readRequest() {
- return PropertyHelper.getReadRequest(
- ADMINSETTING_NAME_PROPERTY_ID,
- ADMINSETTING_CONTENT_PROPERTY_ID,
- ADMINSETTING_SETTING_TYPE_PROPERTY_ID,
- ADMINSETTING_UPDATED_BY_PROPERTY_ID,
- ADMINSETTING_UPDATE_TIMESTAMP_PROPERTY_ID);
- }
-
- private Request createRequest(AdminSettingEntity entity) {
- Map<String, Object> properties = new HashMap<>();
- properties.put(ADMINSETTING_NAME_PROPERTY_ID, entity.getName());
- properties.put(ADMINSETTING_CONTENT_PROPERTY_ID, entity.getContent());
- properties.put(ADMINSETTING_UPDATED_BY_PROPERTY_ID, entity.getUpdatedBy());
- properties.put(ADMINSETTING_SETTING_TYPE_PROPERTY_ID, entity.getSettingType());
- return PropertyHelper.getCreateRequest(Collections.singleton(properties), null);
- }
-
- private Request updateRequest(AdminSettingEntity entity) {
- Map<String, Object> properties = new HashMap<>();
- properties.put(ADMINSETTING_NAME_PROPERTY_ID, entity.getName());
- properties.put(ADMINSETTING_CONTENT_PROPERTY_ID, entity.getContent());
- properties.put(ADMINSETTING_SETTING_TYPE_PROPERTY_ID, entity.getSettingType());
- return PropertyHelper.getUpdateRequest(properties, null);
- }
-
- private void setupAuthenticationForClusterUser() {
- SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createClusterUser());
- }
-
- private void setupAuthenticationForAdmin() {
- SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
- }
-
- private AdminSettingEntity newEntity(String name) {
- AdminSettingEntity entity = new AdminSettingEntity();
- entity.setName(name);
- entity.setContent(RandomStringUtils.randomAlphabetic(10));
- entity.setSettingType(RandomStringUtils.randomAlphabetic(5));
- entity.setUpdatedBy("ambari");
- entity.setUpdateTimestamp(System.currentTimeMillis());
- return entity;
- }
-
- private void assertEqualsEntityAndResource(AdminSettingEntity entity, Resource resource) {
- assertEquals(entity.getName(), resource.getPropertyValue(ADMINSETTING_NAME_PROPERTY_ID));
- assertEquals(entity.getSettingType(), resource.getPropertyValue(ADMINSETTING_SETTING_TYPE_PROPERTY_ID));
- assertEquals(entity.getContent(), resource.getPropertyValue(ADMINSETTING_CONTENT_PROPERTY_ID));
- assertEquals(entity.getUpdatedBy(), resource.getPropertyValue(ADMINSETTING_UPDATED_BY_PROPERTY_ID));
- assertEquals(entity.getUpdateTimestamp(), resource.getPropertyValue(ADMINSETTING_UPDATE_TIMESTAMP_PROPERTY_ID));
- }
-
- private void setPrivateField(Object o, String field, Object value) throws Exception{
- Class<?> c = o.getClass();
- Field f = c.getDeclaredField(field);
- f.setAccessible(true);
- f.set(o, value);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/SettingResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/SettingResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/SettingResourceProviderTest.java
new file mode 100644
index 0000000..c133220
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/SettingResourceProviderTest.java
@@ -0,0 +1,355 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.controller.internal;
+
+import com.google.common.collect.Lists;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.RequestStatus;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException;
+import org.apache.ambari.server.controller.utilities.PredicateBuilder;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.orm.dao.SettingDAO;
+import org.apache.ambari.server.orm.entities.SettingEntity;
+import org.apache.ambari.server.security.TestAuthenticationFactory;
+import org.apache.ambari.server.security.authorization.AuthorizationException;
+import org.apache.ambari.server.security.authorization.AuthorizationHelper;
+import org.apache.commons.lang.RandomStringUtils;
+import org.easymock.Capture;
+import org.easymock.IMocksControl;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.security.core.context.SecurityContextHolder;
+
+import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import static org.apache.ambari.server.controller.internal.SettingResourceProvider.SETTING_NAME_PROPERTY_ID;
+import static org.apache.ambari.server.controller.internal.SettingResourceProvider.SETTING_SETTING_TYPE_PROPERTY_ID;
+import static org.apache.ambari.server.controller.internal.SettingResourceProvider.SETTING_CONTENT_PROPERTY_ID;
+import static org.apache.ambari.server.controller.internal.SettingResourceProvider.SETTING_UPDATED_BY_PROPERTY_ID;
+import static org.apache.ambari.server.controller.internal.SettingResourceProvider.SETTING_UPDATE_TIMESTAMP_PROPERTY_ID;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.createControl;
+
+import static org.junit.Assert.assertEquals;
+
+public class SettingResourceProviderTest {
+ IMocksControl mockControl;
+ SettingDAO dao;
+ SettingResourceProvider resourceProvider;
+
+
+ @Before
+ public void setUp() throws Exception {
+ mockControl = createControl();
+ dao = mockControl.createMock(SettingDAO.class);
+ resourceProvider = new SettingResourceProvider();
+ setPrivateField(resourceProvider, "dao", dao);
+ }
+
+ @After
+ public void tearDown() {
+ mockControl.verify();
+ SecurityContextHolder.getContext().setAuthentication(null);
+ mockControl.reset();
+ }
+
+ @Test(expected = AuthorizationException.class)
+ public void testGetResources_instance_noAuth() throws Exception {
+ getResources_instance(newEntity("motd"), readRequest());
+ }
+
+ @Test
+ public void testGetResources_instance_clusterUser() throws Exception {
+ setupAuthenticationForClusterUser();
+ String name = "motd";
+ SettingEntity entity = newEntity(name);
+
+ Set<Resource> response = getResources_instance(entity, readRequest());
+ assertEquals(1, response.size());
+ Resource resource = response.iterator().next();
+ assertEqualsEntityAndResource(entity, resource);
+ }
+
+ @Test
+ public void testGetResources_instance_admin() throws Exception {
+ setupAuthenticationForAdmin();
+ SettingEntity entity = newEntity("motd");
+ Set<Resource> response = getResources_instance(entity, readRequest());
+ assertEquals(1, response.size());
+ Resource resource = response.iterator().next();
+ assertEqualsEntityAndResource(entity, resource);
+ }
+
+ @Test(expected = AuthorizationException.class)
+ public void testGetResources_collection_noAuth() throws Exception {
+ mockControl.replay();
+ Request request = PropertyHelper.getReadRequest(
+ SETTING_NAME_PROPERTY_ID,
+ SETTING_CONTENT_PROPERTY_ID,
+ SETTING_SETTING_TYPE_PROPERTY_ID,
+ SETTING_UPDATED_BY_PROPERTY_ID,
+ SETTING_UPDATE_TIMESTAMP_PROPERTY_ID);
+ resourceProvider.getResources(request, null);
+ }
+
+ @Test
+ public void testGetResources_collection_clusterUser() throws Exception {
+ setupAuthenticationForClusterUser();
+
+ SettingEntity entity1 = newEntity("motd");
+ SettingEntity entity2 = newEntity("ldap");
+ Request request = PropertyHelper.getReadRequest(
+ SETTING_NAME_PROPERTY_ID,
+ SETTING_CONTENT_PROPERTY_ID,
+ SETTING_SETTING_TYPE_PROPERTY_ID,
+ SETTING_UPDATED_BY_PROPERTY_ID,
+ SETTING_UPDATE_TIMESTAMP_PROPERTY_ID);
+
+ expect(dao.findAll()).andReturn(Lists.newArrayList(entity1, entity2));
+ mockControl.replay();
+
+ Set<Resource> response = resourceProvider.getResources(request, null);
+ assertEquals(2, response.size());
+ Map<Object, Resource> resourceMap = new HashMap<>();
+ Iterator<Resource> resourceIterator = response.iterator();
+ Resource nextResource = resourceIterator.next();
+ resourceMap.put(nextResource.getPropertyValue(SETTING_NAME_PROPERTY_ID), nextResource);
+ nextResource = resourceIterator.next();
+ resourceMap.put(nextResource.getPropertyValue(SETTING_NAME_PROPERTY_ID), nextResource);
+ assertEqualsEntityAndResource(entity1, resourceMap.get(entity1.getName()));
+ assertEqualsEntityAndResource(entity2, resourceMap.get(entity2.getName()));
+ }
+
+ @Test
+ public void testGetResources_collection_admin() throws Exception {
+ setupAuthenticationForAdmin();
+
+ SettingEntity entity1 = newEntity("motd");
+ SettingEntity entity2 = newEntity("ldap");
+ Request request = PropertyHelper.getReadRequest(
+ SETTING_NAME_PROPERTY_ID,
+ SETTING_CONTENT_PROPERTY_ID,
+ SETTING_SETTING_TYPE_PROPERTY_ID,
+ SETTING_UPDATED_BY_PROPERTY_ID,
+ SETTING_UPDATE_TIMESTAMP_PROPERTY_ID);
+ expect(dao.findAll()).andReturn(Lists.newArrayList(entity1, entity2));
+ mockControl.replay();
+
+ Set<Resource> response = resourceProvider.getResources(request, null);
+ assertEquals(2, response.size());
+ Map<Object, Resource> resourceMap = new HashMap<>();
+ Iterator<Resource> resourceIterator = response.iterator();
+ Resource nextResource = resourceIterator.next();
+ resourceMap.put(nextResource.getPropertyValue(SETTING_NAME_PROPERTY_ID), nextResource);
+ nextResource = resourceIterator.next();
+ resourceMap.put(nextResource.getPropertyValue(SETTING_NAME_PROPERTY_ID), nextResource);
+ assertEqualsEntityAndResource(entity1, resourceMap.get(entity1.getName()));
+ assertEqualsEntityAndResource(entity2, resourceMap.get(entity2.getName()));
+ }
+
+ @Test(expected = AuthorizationException.class)
+ public void testCreateResource_noAuth() throws Exception {
+ mockControl.replay();
+ resourceProvider.createResources(createRequest(newEntity("moted")));
+ }
+
+ @Test(expected = AuthorizationException.class)
+ public void testCreateResource_clusterUser() throws Exception {
+ setupAuthenticationForClusterUser();
+ mockControl.replay();
+ resourceProvider.createResources(createRequest(newEntity("motd")));
+ }
+
+ @Test
+ public void testCreateResource_admin() throws Exception {
+ setupAuthenticationForAdmin();
+ SettingEntity entity = newEntity("motd");
+ Capture<SettingEntity> entityCapture = Capture.newInstance();
+ Request request = createRequest(entity);
+
+ expect(dao.findByName(entity.getName())).andReturn(null);
+ dao.create(capture(entityCapture));
+ mockControl.replay();
+
+ RequestStatus response = resourceProvider.createResources(request);
+ assertEquals(RequestStatus.Status.Complete, response.getStatus());
+ Set<Resource> associatedResources = response.getAssociatedResources();
+ assertEquals(1, associatedResources.size());
+ SettingEntity capturedEntity = entityCapture.getValue();
+ assertEquals(entity.getName(), capturedEntity.getName());
+ assertEquals(entity.getContent(), capturedEntity.getContent());
+ assertEquals(entity.getSettingType(), capturedEntity.getSettingType());
+ assertEquals(AuthorizationHelper.getAuthenticatedName(), capturedEntity.getUpdatedBy());
+ }
+
+ @Test(expected = ResourceAlreadyExistsException.class)
+ public void testCreateDuplicateResource() throws Exception {
+ setupAuthenticationForAdmin();
+ SettingEntity entity = newEntity("motd");
+ Request request = createRequest(entity);
+
+ expect(dao.findByName(entity.getName())).andReturn(entity);
+ mockControl.replay();
+ resourceProvider.createResources(request);
+ }
+
+ @Test(expected = AuthorizationException.class)
+ public void testUpdateResources_noAuth() throws Exception {
+ mockControl.replay();
+ resourceProvider.updateResources(updateRequest(newEntity("motd")), null);
+ }
+
+ @Test(expected = AuthorizationException.class)
+ public void testUpdateResources_clusterUser() throws Exception {
+ setupAuthenticationForClusterUser();
+ mockControl.replay();
+ resourceProvider.updateResources(updateRequest(newEntity("motd")), null);
+ }
+
+ @Test
+ public void testUpdateResources_admin() throws Exception {
+ setupAuthenticationForAdmin();
+ String name = "motd";
+ SettingEntity oldEntity = newEntity(name);
+ SettingEntity updatedEntity = oldEntity.clone();
+ updatedEntity.setContent("{text}");
+ updatedEntity.setSettingType("new-type");
+
+ PredicateBuilder pb = new PredicateBuilder();
+ Predicate predicate = pb.begin().property(SETTING_NAME_PROPERTY_ID).equals(name).end().toPredicate();
+ Capture<SettingEntity> capture = Capture.newInstance();
+
+ expect(dao.findByName(name)).andReturn(oldEntity);
+ expect(dao.merge(capture(capture))).andReturn(updatedEntity);
+ mockControl.replay();
+
+ RequestStatus response = resourceProvider.updateResources(updateRequest(updatedEntity), predicate);
+ SettingEntity capturedEntity = capture.getValue();
+ assertEquals(RequestStatus.Status.Complete, response.getStatus());
+ assertEquals(updatedEntity.getId(), capturedEntity.getId());
+ assertEquals(updatedEntity.getName(), capturedEntity.getName());
+ assertEquals(updatedEntity.getSettingType(), capturedEntity.getSettingType());
+ assertEquals(updatedEntity.getContent(), capturedEntity.getContent());
+ assertEquals(AuthorizationHelper.getAuthenticatedName(), capturedEntity.getUpdatedBy());
+ }
+
+ @Test(expected = AuthorizationException.class)
+ public void testDeleteResources_noAuth() throws Exception {
+ mockControl.replay();
+ resourceProvider.deleteResources(null);
+ }
+
+
+ @Test(expected = AuthorizationException.class)
+ public void testDeleteResources_clusterUser() throws Exception {
+ setupAuthenticationForClusterUser();
+ mockControl.replay();
+ resourceProvider.deleteResources(null);
+ }
+
+ @Test
+ public void testDeleteResources() throws Exception {
+ setupAuthenticationForAdmin();
+
+ String name = "motd";
+ PredicateBuilder pb = new PredicateBuilder();
+ Predicate predicate = pb.begin().property(SETTING_NAME_PROPERTY_ID).equals(name).end().toPredicate();
+ dao.removeByName(name);
+ mockControl.replay();
+ resourceProvider.deleteResources(predicate);
+ }
+
+ private Set<Resource> getResources_instance(SettingEntity entity, Request request) throws Exception {
+ String name = entity.getName();
+ PredicateBuilder pb = new PredicateBuilder();
+ Predicate predicate = pb.begin().property(SETTING_NAME_PROPERTY_ID).equals(name).end().toPredicate();
+
+ expect(dao.findByName(name)).andReturn(entity).anyTimes();
+ mockControl.replay();
+ return resourceProvider.getResources(request, predicate);
+ }
+
+
+ private Request readRequest() {
+ return PropertyHelper.getReadRequest(
+ SETTING_NAME_PROPERTY_ID,
+ SETTING_CONTENT_PROPERTY_ID,
+ SETTING_SETTING_TYPE_PROPERTY_ID,
+ SETTING_UPDATED_BY_PROPERTY_ID,
+ SETTING_UPDATE_TIMESTAMP_PROPERTY_ID);
+ }
+
+ private Request createRequest(SettingEntity entity) {
+ Map<String, Object> properties = new HashMap<>();
+ properties.put(SETTING_NAME_PROPERTY_ID, entity.getName());
+ properties.put(SETTING_CONTENT_PROPERTY_ID, entity.getContent());
+ properties.put(SETTING_UPDATED_BY_PROPERTY_ID, entity.getUpdatedBy());
+ properties.put(SETTING_SETTING_TYPE_PROPERTY_ID, entity.getSettingType());
+ return PropertyHelper.getCreateRequest(Collections.singleton(properties), null);
+ }
+
+ private Request updateRequest(SettingEntity entity) {
+ Map<String, Object> properties = new HashMap<>();
+ properties.put(SETTING_NAME_PROPERTY_ID, entity.getName());
+ properties.put(SETTING_CONTENT_PROPERTY_ID, entity.getContent());
+ properties.put(SETTING_SETTING_TYPE_PROPERTY_ID, entity.getSettingType());
+ return PropertyHelper.getUpdateRequest(properties, null);
+ }
+
+ private void setupAuthenticationForClusterUser() {
+ SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createClusterUser());
+ }
+
+ private void setupAuthenticationForAdmin() {
+ SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
+ }
+
+ private SettingEntity newEntity(String name) {
+ SettingEntity entity = new SettingEntity();
+ entity.setName(name);
+ entity.setContent(RandomStringUtils.randomAlphabetic(10));
+ entity.setSettingType(RandomStringUtils.randomAlphabetic(5));
+ entity.setUpdatedBy("ambari");
+ entity.setUpdateTimestamp(System.currentTimeMillis());
+ return entity;
+ }
+
+ private void assertEqualsEntityAndResource(SettingEntity entity, Resource resource) {
+ assertEquals(entity.getName(), resource.getPropertyValue(SETTING_NAME_PROPERTY_ID));
+ assertEquals(entity.getSettingType(), resource.getPropertyValue(SETTING_SETTING_TYPE_PROPERTY_ID));
+ assertEquals(entity.getContent(), resource.getPropertyValue(SETTING_CONTENT_PROPERTY_ID));
+ assertEquals(entity.getUpdatedBy(), resource.getPropertyValue(SETTING_UPDATED_BY_PROPERTY_ID));
+ assertEquals(entity.getUpdateTimestamp(), resource.getPropertyValue(SETTING_UPDATE_TIMESTAMP_PROPERTY_ID));
+ }
+
+ private void setPrivateField(Object o, String field, Object value) throws Exception{
+ Class<?> c = o.getClass();
+ Field f = c.getDeclaredField(field);
+ f.setAccessible(true);
+ f.set(o, value);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AdminSettingDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AdminSettingDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AdminSettingDAOTest.java
deleted file mode 100644
index 8258974..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AdminSettingDAOTest.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.server.orm.dao;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import org.apache.ambari.server.orm.GuiceJpaInitializer;
-import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
-import org.apache.ambari.server.orm.OrmTestHelper;
-import org.apache.ambari.server.orm.entities.AdminSettingEntity;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNull;
-
-public class AdminSettingDAOTest {
- private Injector injector;
- private AdminSettingDAO dao;
-
- @Before
- public void setUp() {
- injector = Guice.createInjector(new InMemoryDefaultTestModule());
- dao = injector.getInstance(AdminSettingDAO.class);
- injector.getInstance(GuiceJpaInitializer.class);
- injector.getInstance(OrmTestHelper.class).createCluster();
- }
-
- @Test
- public void testCRUD() {
- Map<String, AdminSettingEntity> entities = new HashMap<>();
- //Create
- for (int i=0; i < 3; i++) {
- AdminSettingEntity entity = new AdminSettingEntity();
- entity.setName("motd" + i);
- entity.setContent("test content" + i);
- entity.setUpdatedBy("ambari");
- entity.setSettingType("ambari-server");
- entity.setUpdateTimestamp(System.currentTimeMillis());
- entities.put(entity.getName(), entity);
- dao.create(entity);
- }
-
- //Retrieve
- retrieveAndValidateSame(entities);
- assertEquals(entities.size(), dao.findAll().size());
-
- //Should return null if doesn't exist.
- assertNull(dao.findByName("does-not-exist"));
-
-
- //Update
- for(Map.Entry<String, AdminSettingEntity> entry : entities.entrySet()) {
- entry.getValue().setContent(Objects.toString(Math.random()));
- dao.merge(entry.getValue());
- }
-
- retrieveAndValidateSame(entities);
- assertEquals(entities.size(), dao.findAll().size());
-
- //Delete
- for(Map.Entry<String, AdminSettingEntity> entry : entities.entrySet()) {
- dao.removeByName(entry.getKey());
- }
- assertEquals(0, dao.findAll().size());
- }
-
- private void retrieveAndValidateSame(Map<String, AdminSettingEntity> entities) {
- for(Map.Entry<String, AdminSettingEntity> entry : entities.entrySet()) {
- String name = entry.getKey();
- assertEquals(entry.getValue(), dao.findByName(name));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/SettingDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/SettingDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/SettingDAOTest.java
new file mode 100644
index 0000000..77f87be
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/SettingDAOTest.java
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.orm.dao;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import org.apache.ambari.server.orm.GuiceJpaInitializer;
+import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.OrmTestHelper;
+import org.apache.ambari.server.orm.entities.SettingEntity;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNull;
+
+public class SettingDAOTest {
+ private Injector injector;
+ private SettingDAO dao;
+
+ @Before
+ public void setUp() {
+ injector = Guice.createInjector(new InMemoryDefaultTestModule());
+ dao = injector.getInstance(SettingDAO.class);
+ injector.getInstance(GuiceJpaInitializer.class);
+ injector.getInstance(OrmTestHelper.class).createCluster();
+ }
+
+ @Test
+ public void testCRUD() {
+ Map<String, SettingEntity> entities = new HashMap<>();
+ //Create
+ for (int i=0; i < 3; i++) {
+ SettingEntity entity = new SettingEntity();
+ entity.setName("motd" + i);
+ entity.setContent("test content" + i);
+ entity.setUpdatedBy("ambari");
+ entity.setSettingType("ambari-server");
+ entity.setUpdateTimestamp(System.currentTimeMillis());
+ entities.put(entity.getName(), entity);
+ dao.create(entity);
+ }
+
+ //Retrieve
+ retrieveAndValidateSame(entities);
+ assertEquals(entities.size(), dao.findAll().size());
+
+ //Should return null if doesn't exist.
+ assertNull(dao.findByName("does-not-exist"));
+
+
+ //Update
+ for(Map.Entry<String, SettingEntity> entry : entities.entrySet()) {
+ entry.getValue().setContent(Objects.toString(Math.random()));
+ dao.merge(entry.getValue());
+ }
+
+ retrieveAndValidateSame(entities);
+ assertEquals(entities.size(), dao.findAll().size());
+
+ //Delete
+ for(Map.Entry<String, SettingEntity> entry : entities.entrySet()) {
+ dao.removeByName(entry.getKey());
+ }
+ assertEquals(0, dao.findAll().size());
+ }
+
+ private void retrieveAndValidateSame(Map<String, SettingEntity> entities) {
+ for(Map.Entry<String, SettingEntity> entry : entities.entrySet()) {
+ String name = entry.getKey();
+ assertEquals(entry.getValue(), dao.findByName(name));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/AdminSettingEntityTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/AdminSettingEntityTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/AdminSettingEntityTest.java
deleted file mode 100644
index a7cba23..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/AdminSettingEntityTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.server.orm.entities;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import static junit.framework.Assert.assertEquals;
-
-/**
- * AdminSettingEntity unit tests.
- */
-public class AdminSettingEntityTest {
-
- @Test
- public void testSetGetId() {
- long id = 1000;
- AdminSettingEntity entity = new AdminSettingEntity();
- entity.setId(id);
- assertEquals(id, entity.getId());
- }
-
- @Test
- public void testSetGetName() {
- String name = "motd";
- AdminSettingEntity entity = new AdminSettingEntity();
- entity.setName(name);
- assertEquals(name, entity.getName());
- }
-
- @Test
- public void testSetGetSettingType() {
- String settingType = "ambari-server";
- AdminSettingEntity entity = new AdminSettingEntity();
- entity.setSettingType(settingType);
- assertEquals(settingType, entity.getSettingType());
- }
-
- @Test
- public void testSetGetContent() {
- String content = "{tag:random-tag, text:random-text}";
- AdminSettingEntity entity = new AdminSettingEntity();
- entity.setContent(content);
- assertEquals(content, entity.getContent());
- }
-
- @Test
- public void testSetGetUpdatedBy() {
- String updatedBy = "ambari";
- AdminSettingEntity entity = new AdminSettingEntity();
- entity.setUpdatedBy(updatedBy);
- assertEquals(updatedBy, entity.getUpdatedBy());
- }
-
- @Test
- public void testSetGetUpdatedTimeStamp() {
- long updateTimeStamp = 1234567890;
- AdminSettingEntity entity = new AdminSettingEntity();
- entity.setUpdateTimestamp(updateTimeStamp);
- assertEquals(updateTimeStamp, entity.getUpdateTimestamp());
- }
-
- @Test
- public void testEquals() {
- AdminSettingEntity entity = new AdminSettingEntity();
- entity.setId(1);
- entity.setName("motd");
- entity.setContent("{tag:random-tag, text:random-text}");
- entity.setSettingType("ambari-server");
- entity.setUpdatedBy("ambari");
- entity.setUpdateTimestamp(1234567890);
- AdminSettingEntity newEntity = entity.clone();
- assertEquals(entity, newEntity);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/774d689e/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/SettingEntityTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/SettingEntityTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/SettingEntityTest.java
new file mode 100644
index 0000000..defe948
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/SettingEntityTest.java
@@ -0,0 +1,90 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.orm.entities;
+
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+
+/**
+ * SettingEntity unit tests.
+ */
+public class SettingEntityTest {
+
+ @Test
+ public void testSetGetId() {
+ long id = 1000;
+ SettingEntity entity = new SettingEntity();
+ entity.setId(id);
+ assertEquals(id, entity.getId());
+ }
+
+ @Test
+ public void testSetGetName() {
+ String name = "motd";
+ SettingEntity entity = new SettingEntity();
+ entity.setName(name);
+ assertEquals(name, entity.getName());
+ }
+
+ @Test
+ public void testSetGetSettingType() {
+ String settingType = "ambari-server";
+ SettingEntity entity = new SettingEntity();
+ entity.setSettingType(settingType);
+ assertEquals(settingType, entity.getSettingType());
+ }
+
+ @Test
+ public void testSetGetContent() {
+ String content = "{tag:random-tag, text:random-text}";
+ SettingEntity entity = new SettingEntity();
+ entity.setContent(content);
+ assertEquals(content, entity.getContent());
+ }
+
+ @Test
+ public void testSetGetUpdatedBy() {
+ String updatedBy = "ambari";
+ SettingEntity entity = new SettingEntity();
+ entity.setUpdatedBy(updatedBy);
+ assertEquals(updatedBy, entity.getUpdatedBy());
+ }
+
+ @Test
+ public void testSetGetUpdatedTimeStamp() {
+ long updateTimeStamp = 1234567890;
+ SettingEntity entity = new SettingEntity();
+ entity.setUpdateTimestamp(updateTimeStamp);
+ assertEquals(updateTimeStamp, entity.getUpdateTimestamp());
+ }
+
+ @Test
+ public void testEquals() {
+ SettingEntity entity = new SettingEntity();
+ entity.setId(1);
+ entity.setName("motd");
+ entity.setContent("{tag:random-tag, text:random-text}");
+ entity.setSettingType("ambari-server");
+ entity.setUpdatedBy("ambari");
+ entity.setUpdateTimestamp(1234567890);
+ SettingEntity newEntity = entity.clone();
+ assertEquals(entity, newEntity);
+ }
+
+}