/** * Tests {@link ExternalResource#clone()}. * * @throws CloneNotSupportedException if it fails. */ @Test public void testClone() throws CloneNotSupportedException { String name = "name"; String description = "description"; String id = "id"; ExternalResource resource = new ExternalResource(name, description, id, true, new LinkedList<MetadataValue>()); String me = "me"; resource.setReserved( new StashInfo( StashInfo.StashType.INTERNAL, me, new Lease(Calendar.getInstance(), "iso"), "key")); TreeStructureUtil.addValue(resource, "value", "descript", "some", "path"); ExternalResource other = resource.clone(); assertEquals(name, other.getName()); assertEquals(id, other.getId()); assertNotNull(other.getReserved()); assertNotSame(resource.getReserved(), other.getReserved()); assertEquals(resource.getReserved().getStashedBy(), other.getReserved().getStashedBy()); assertNotSame(resource.getReserved().getLease(), other.getReserved().getLease()); assertEquals( resource.getReserved().getLease().getSlaveIsoTime(), other.getReserved().getLease().getSlaveIsoTime()); assertNotSame( TreeStructureUtil.getPath(resource, "some", "path"), TreeStructureUtil.getPath(other, "some", "path")); assertEquals( TreeStructureUtil.getPath(resource, "some", "path").getValue(), TreeStructureUtil.getPath(other, "some", "path").getValue()); assertTrue(other.isEnabled()); }
/** Tests {@link ExternalResource#toJson()}. */ @PrepareForTest(Hudson.class) @Test public void testToJson() { Hudson hudson = MockUtils.mockHudson(); MockUtils.mockMetadataValueDescriptors(hudson); String name = "name"; String description = "description"; String id = "id"; ExternalResource resource = new ExternalResource(name, description, id, true, new LinkedList<MetadataValue>()); String me = "me"; resource.setReserved( new StashInfo( StashInfo.StashType.INTERNAL, me, new Lease(Calendar.getInstance(), "iso"), "key")); TreeStructureUtil.addValue(resource, "value", "descript", "some", "path"); JSONObject json = resource.toJson(); assertEquals(name, json.getString(JsonUtils.NAME)); assertEquals(id, json.getString(JSON_ATTR_ID)); assertTrue(json.getBoolean(JSON_ATTR_ENABLED)); assertTrue(json.getJSONObject(JSON_ATTR_LOCKED).isNullObject()); JSONObject reserved = json.getJSONObject(JSON_ATTR_RESERVED); assertNotNull(reserved); assertEquals(StashInfo.StashType.INTERNAL.name(), reserved.getString(Constants.JSON_ATTR_TYPE)); assertEquals(me, reserved.getString(Constants.JSON_ATTR_STASHED_BY)); assertEquals(1, json.getJSONArray(JsonUtils.CHILDREN).size()); }