Move files under newresource package to resource package

Change-Id: Ifedb99be4671ada97fafe3ecfd196939207baa86
diff --git a/core/api/src/test/java/org/onosproject/net/resource/ContinuousResourceIdTest.java b/core/api/src/test/java/org/onosproject/net/resource/ContinuousResourceIdTest.java
new file mode 100644
index 0000000..8b91bbd
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/net/resource/ContinuousResourceIdTest.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed 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.onosproject.net.resource;
+
+import com.google.common.testing.EqualsTester;
+import org.junit.Test;
+import org.onlab.util.Bandwidth;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Unit test for ContinuousResourceId.
+ */
+public class ContinuousResourceIdTest {
+
+    private static final DeviceId D1 = DeviceId.deviceId("of:001");
+    private static final PortNumber P1 = PortNumber.portNumber(1);
+    private static final Bandwidth BW1 = Bandwidth.gbps(2);
+    private static final Bandwidth BW2 = Bandwidth.gbps(1);
+
+    @Test
+    public void testEquality() {
+        ContinuousResourceId id1 = Resources.continuous(D1, P1, Bandwidth.class)
+                .resource(BW1.bps()).id();
+        // intentionally set a different value
+        ContinuousResourceId sameAsId1 = Resources.continuous(D1, P1, Bandwidth.class)
+                .resource(BW2.bps()).id();
+
+        new EqualsTester()
+                .addEqualityGroup(id1, sameAsId1);
+    }
+
+    @Test
+    public void testSimpleTypeName() {
+        ContinuousResourceId id1 = Resources.continuous(D1, P1, Bandwidth.class).resource(BW1.bps()).id();
+
+        assertThat(id1.simpleTypeName(), is("Bandwidth"));
+    }
+}
diff --git a/core/api/src/test/java/org/onosproject/net/resource/ContinuousResourceTest.java b/core/api/src/test/java/org/onosproject/net/resource/ContinuousResourceTest.java
new file mode 100644
index 0000000..88f0a1c
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/net/resource/ContinuousResourceTest.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed 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.onosproject.net.resource;
+
+import com.google.common.testing.EqualsTester;
+import org.junit.Test;
+import org.onlab.packet.VlanId;
+import org.onlab.util.Bandwidth;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+
+import java.util.Optional;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.*;
+
+/**
+ * Unit test for ContinuousResource.
+ */
+public class ContinuousResourceTest {
+
+    private static final DeviceId D1 = DeviceId.deviceId("of:001");
+    private static final PortNumber P1 = PortNumber.portNumber(1);
+    private static final Bandwidth BW1 = Bandwidth.gbps(2);
+
+    @Test
+    public void testEquals() {
+        ContinuousResource resource1 = Resources.continuous(D1, P1, Bandwidth.class)
+                .resource(BW1.bps());
+        ContinuousResource sameAsResource1 = Resources.continuous(D1, P1, Bandwidth.class)
+                .resource(BW1.bps());
+
+        new EqualsTester()
+                .addEqualityGroup(resource1, sameAsResource1)
+                .testEquals();
+    }
+
+    @Test
+    public void testTypeOf() {
+        ContinuousResource continuous = Resources.continuous(D1, P1, Bandwidth.class)
+                .resource(BW1.bps());
+
+        assertThat(continuous.isTypeOf(DeviceId.class), is(false));
+        assertThat(continuous.isTypeOf(PortNumber.class), is(false));
+        assertThat(continuous.isTypeOf(Bandwidth.class), is(true));
+    }
+
+    @Test
+    public void testSubTypeOf() {
+        ContinuousResource continuous = Resources.continuous(D1, P1, Bandwidth.class)
+                .resource(BW1.bps());
+
+        assertThat(continuous.isSubTypeOf(DeviceId.class), is(true));
+        assertThat(continuous.isSubTypeOf(PortNumber.class), is(true));
+        assertThat(continuous.isSubTypeOf(Bandwidth.class), is(true));
+        assertThat(continuous.isSubTypeOf(VlanId.class), is(false));
+    }
+
+    @Test
+    public void testSubTypeOfObject() {
+        ContinuousResource continuous = Resources.continuous(D1, P1, Bandwidth.class)
+                .resource(BW1.bps());
+
+        assertThat(continuous.isSubTypeOf(Object.class), is(true));
+    }
+
+    @Test
+    public void testValueAsPrimitiveDouble() {
+        ContinuousResource resource = Resources.continuous(D1, P1, Bandwidth.class)
+                .resource(BW1.bps());
+
+        Optional<Double> volume = resource.valueAs(double.class);
+        assertThat(volume.get(), is(BW1.bps()));
+    }
+
+    @Test
+    public void testValueAsDouble() {
+        ContinuousResource resource = Resources.continuous(D1, P1, Bandwidth.class)
+                .resource(BW1.bps());
+
+        Optional<Double> value = resource.valueAs(Double.class);
+        assertThat(value.get(), is(BW1.bps()));
+    }
+
+    @Test
+    public void testValueAsObject() {
+        ContinuousResource resource = Resources.continuous(D1, P1, Bandwidth.class)
+                .resource(BW1.bps());
+
+        Optional<Double> value = resource.valueAs(Double.class);
+        assertThat(value.get(), is(BW1.bps()));
+    }
+
+    @Test
+    public void testValueAsIncompatibleType() {
+        ContinuousResource resource = Resources.continuous(D1, P1, Bandwidth.class)
+                .resource(BW1.bps());
+
+        Optional<VlanId> value = resource.valueAs(VlanId.class);
+        assertThat(value, is(Optional.empty()));
+    }
+}
diff --git a/core/api/src/test/java/org/onosproject/net/resource/DiscreteResourceIdTest.java b/core/api/src/test/java/org/onosproject/net/resource/DiscreteResourceIdTest.java
new file mode 100644
index 0000000..7dfcb9f
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/net/resource/DiscreteResourceIdTest.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed 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.onosproject.net.resource;
+
+import com.google.common.testing.EqualsTester;
+import org.junit.Test;
+import org.onlab.packet.VlanId;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Unit test for DiscreteResourceId.
+ */
+public class DiscreteResourceIdTest {
+
+    private static final DeviceId D1 = DeviceId.deviceId("of:001");
+    private static final DeviceId D2 = DeviceId.deviceId("of:002");
+    private static final PortNumber P1 = PortNumber.portNumber(1);
+    private static final VlanId VLAN1 = VlanId.vlanId((short) 100);
+
+    @Test
+    public void testEquality() {
+        DiscreteResourceId id1 = Resources.discrete(D1, P1, VLAN1).id();
+        DiscreteResourceId sameAsId1 = Resources.discrete(D1, P1, VLAN1).id();
+        DiscreteResourceId id2 = Resources.discrete(D2, P1, VLAN1).id();
+
+        new EqualsTester()
+                .addEqualityGroup(id1, sameAsId1)
+                .addEqualityGroup(id2);
+    }
+
+    @Test
+    public void testSimpleTypeName() {
+        DiscreteResourceId id = Resources.discrete(D1, P1, VLAN1).id();
+        assertThat(id.simpleTypeName(), is("VlanId"));
+    }
+
+    @Test
+    public void testSimpleTypeNameOfRoot() {
+        assertThat(ResourceId.ROOT.simpleTypeName(), is("Root"));
+    }
+}
diff --git a/core/api/src/test/java/org/onosproject/net/resource/DiscreteResourceTest.java b/core/api/src/test/java/org/onosproject/net/resource/DiscreteResourceTest.java
new file mode 100644
index 0000000..bb019a7
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/net/resource/DiscreteResourceTest.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed 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.onosproject.net.resource;
+
+import com.google.common.testing.EqualsTester;
+import org.junit.Test;
+import org.onlab.packet.VlanId;
+import org.onlab.util.Bandwidth;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+
+import java.util.Optional;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.*;
+
+/**
+ * Unit test for DiscreteResource.
+ */
+public class DiscreteResourceTest {
+
+    private static final DeviceId D1 = DeviceId.deviceId("of:001");
+    private static final DeviceId D2 = DeviceId.deviceId("of:002");
+    private static final PortNumber P1 = PortNumber.portNumber(1);
+    private static final VlanId VLAN1 = VlanId.vlanId((short) 100);
+    private static final Bandwidth BW1 = Bandwidth.gbps(2);
+
+    @Test
+    public void testEquals() {
+        DiscreteResource resource1 = Resources.discrete(D1, P1, VLAN1).resource();
+        DiscreteResource sameAsResource1 = Resources.discrete(D1, P1, VLAN1).resource();
+        DiscreteResource resource2 = Resources.discrete(D2, P1, VLAN1).resource();
+
+        new EqualsTester()
+                .addEqualityGroup(resource1, sameAsResource1)
+                .addEqualityGroup(resource2)
+                .testEquals();
+    }
+
+    @Test
+    public void testChild() {
+        DiscreteResource r1 = Resources.discrete(D1).resource().child(P1);
+        DiscreteResource sameAsR2 = Resources.discrete(D1, P1).resource();
+
+        assertThat(r1, is(sameAsR2));
+    }
+
+    @Test
+    public void testThereIsParent() {
+        DiscreteResource resource = Resources.discrete(D1, P1, VLAN1).resource();
+        DiscreteResource parent = Resources.discrete(D1, P1).resource();
+
+        assertThat(resource.parent(), is(Optional.of(parent)));
+    }
+
+    @Test
+    public void testNoParent() {
+        DiscreteResource resource = Resources.discrete(D1).resource();
+
+        assertThat(resource.parent(), is(Optional.of(Resource.ROOT)));
+    }
+
+    @Test
+    public void testTypeOf() {
+        DiscreteResource discrete = Resources.discrete(D1, P1, VLAN1).resource();
+
+        assertThat(discrete.isTypeOf(DeviceId.class), is(false));
+        assertThat(discrete.isTypeOf(PortNumber.class), is(false));
+        assertThat(discrete.isTypeOf(VlanId.class), is(true));
+    }
+
+    @Test
+    public void testSubTypeOf() {
+        DiscreteResource discrete = Resources.discrete(D1, P1, VLAN1).resource();
+
+        assertThat(discrete.isSubTypeOf(DeviceId.class), is(true));
+        assertThat(discrete.isSubTypeOf(PortNumber.class), is(true));
+        assertThat(discrete.isSubTypeOf(VlanId.class), is(true));
+        assertThat(discrete.isSubTypeOf(Bandwidth.class), is(false));
+    }
+
+    @Test
+    public void testSubTypeOfObject() {
+        DiscreteResource discrete = Resources.discrete(D1, P1, VLAN1).resource();
+
+        assertThat(discrete.isSubTypeOf(Object.class), is(true));
+    }
+
+    @Test
+    public void testValueAs() {
+        DiscreteResource resource = Resources.discrete(D1).resource();
+
+        Optional<DeviceId> volume = resource.valueAs(DeviceId.class);
+        assertThat(volume.get(), is(D1));
+    }
+
+    @Test
+    public void testValueOfRoot() {
+        DiscreteResource resource = Resource.ROOT;
+
+        assertThat(resource.valueAs(Object.class), is(Optional.empty()));
+    }
+}
diff --git a/core/api/src/test/java/org/onosproject/net/resource/ResourceAllocationTest.java b/core/api/src/test/java/org/onosproject/net/resource/ResourceAllocationTest.java
new file mode 100644
index 0000000..4e3afce
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/net/resource/ResourceAllocationTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2015-2016 Open Networking Laboratory
+ *
+ * Licensed 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.onosproject.net.resource;
+
+import com.google.common.testing.EqualsTester;
+import org.junit.Test;
+import org.onlab.packet.VlanId;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.intent.IntentId;
+
+public class ResourceAllocationTest {
+
+    private static final DeviceId D1 = DeviceId.deviceId("of:001");
+    private static final DeviceId D2 = DeviceId.deviceId("of:002");
+    private static final PortNumber P1 = PortNumber.portNumber(1);
+    private static final VlanId VLAN1 = VlanId.vlanId((short) 100);
+    private static final IntentId IID1 = IntentId.valueOf(30);
+
+    @Test
+    public void testEquals() {
+        ResourceAllocation alloc1 = new ResourceAllocation(Resources.discrete(D1, P1, VLAN1).resource(), IID1);
+        ResourceAllocation sameAsAlloc1 = new ResourceAllocation(Resources.discrete(D1, P1, VLAN1).resource(), IID1);
+        ResourceAllocation alloc2 = new ResourceAllocation(Resources.discrete(D2, P1, VLAN1).resource(), IID1);
+
+        new EqualsTester()
+                .addEqualityGroup(alloc1, sameAsAlloc1)
+                .addEqualityGroup(alloc2)
+                .testEquals();
+    }
+}
diff --git a/core/api/src/test/java/org/onosproject/net/resource/ResourceIdTest.java b/core/api/src/test/java/org/onosproject/net/resource/ResourceIdTest.java
new file mode 100644
index 0000000..2a0818a
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/net/resource/ResourceIdTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed 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.onosproject.net.resource;
+
+import org.junit.Test;
+import org.onlab.util.Bandwidth;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+
+import java.util.Arrays;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+public class ResourceIdTest {
+    private static final DeviceId D1 = DeviceId.deviceId("a");
+    private static final PortNumber P1 = PortNumber.portNumber(1);
+    private static final Bandwidth BW1 = Bandwidth.gbps(1);
+
+    @Test
+    public void testDiscreteToString() {
+        ResourceId resource = Resources.discrete(D1, P1).id();
+
+        assertThat(resource.toString(), is(Arrays.asList(D1, P1).toString()));
+    }
+
+    @Test
+    public void testContinuousToString() {
+        ResourceId resource = Resources.continuous(D1, P1, Bandwidth.class).id();
+
+        assertThat(resource.toString(), is(Arrays.asList(D1, P1, Bandwidth.class.getSimpleName()).toString()));
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testInitWithNonClassInstance() {
+        Resources.continuous(D1, P1, BW1).id();
+    }
+}