blob: 7de5330a782ee7d48df8cc872f497ef658e4daaa [file] [log] [blame]
/**
* 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 junit.framework.Assert;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
import org.apache.ambari.server.controller.spi.Resource;
import org.junit.Test;
/**
*
*/
public class ResourceImplTest {
@Test
public void testGetType() {
Resource resource = new ResourceImpl(Resource.Type.Cluster);
Assert.assertEquals(Resource.Type.Cluster, resource.getType());
resource = new ResourceImpl(Resource.Type.Service);
Assert.assertEquals(Resource.Type.Service, resource.getType());
resource = new ResourceImpl(Resource.Type.Host);
Assert.assertEquals(Resource.Type.Host, resource.getType());
resource = new ResourceImpl(Resource.Type.Component);
Assert.assertEquals(Resource.Type.Component, resource.getType());
resource = new ResourceImpl(Resource.Type.HostComponent);
Assert.assertEquals(Resource.Type.HostComponent, resource.getType());
}
@Test
public void testSetGetProperty() {
Resource resource = new ResourceImpl(Resource.Type.Cluster);
String propertyId = PropertyHelper.getPropertyId("c1", "p1");
resource.setProperty(propertyId, "foo");
Assert.assertEquals("foo", resource.getPropertyValue(propertyId));
resource.setProperty(propertyId, 1);
Assert.assertEquals(1, resource.getPropertyValue(propertyId));
resource.setProperty(propertyId, (float) 1.99);
Assert.assertEquals((float) 1.99, resource.getPropertyValue(propertyId));
resource.setProperty(propertyId, 1.99);
Assert.assertEquals(1.99, resource.getPropertyValue(propertyId));
resource.setProperty(propertyId, 65L);
Assert.assertEquals(65L, resource.getPropertyValue(propertyId));
}
@Test
public void testCopyConstructor() {
Resource resource = new ResourceImpl(Resource.Type.Cluster);
String p1 = PropertyHelper.getPropertyId(null, "p1");
String p2 = PropertyHelper.getPropertyId("c1", "p2");
String p3 = PropertyHelper.getPropertyId("c1/c2", "p3");
String p4 = PropertyHelper.getPropertyId("c1/c2/c3", "p4");
String p5 = PropertyHelper.getPropertyId("c1", "p5");
resource.setProperty(p1, "foo");
Assert.assertEquals("foo", resource.getPropertyValue(p1));
resource.setProperty(p2, 1);
Assert.assertEquals(1, resource.getPropertyValue(p2));
resource.setProperty(p3, (float) 1.99);
Assert.assertEquals((float) 1.99, resource.getPropertyValue(p3));
resource.setProperty(p4, 1.99);
Assert.assertEquals(1.99, resource.getPropertyValue(p4));
resource.setProperty(p5, 65L);
Assert.assertEquals(65L, resource.getPropertyValue(p5));
Resource copy = new ResourceImpl(resource);
Assert.assertEquals("foo", copy.getPropertyValue(p1));
Assert.assertEquals(1, copy.getPropertyValue(p2));
Assert.assertEquals((float) 1.99, copy.getPropertyValue(p3));
Assert.assertEquals(1.99, copy.getPropertyValue(p4));
Assert.assertEquals(65L, copy.getPropertyValue(p5));
}
}