/** 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());
  }
예제 #2
0
 public void actionPerformed(final ActionEvent arg0) {
   final ProgressUtilities progUtil = new ProgressUtilities();
   final MapController mapController = Controller.getCurrentModeController().getMapController();
   final Collection<NodeModel> nodes = mapController.getSelectedNodes();
   final ViewerController vc =
       ((ViewerController)
           Controller.getCurrentController()
               .getModeController()
               .getExtension(ViewerController.class));
   final NodeModel selectedNode = mapController.getSelectedNode();
   final ExternalResource extRes = (ExternalResource) vc.createExtension(selectedNode);
   if (extRes != null) {
     final File file = new File(extRes.getAbsoluteUri(selectedNode.getMap()));
     for (final NodeModel node : nodes) {
       if (!progUtil.hasExternalResource(node)) {
         vc.paste(file, node, node.isLeft());
       }
     }
   }
 }
 /** Tests {@link ExternalResource#isEnabled()} when enables is set to true. */
 @Test
 public void testIsEnabledTrue() {
   ExternalResource resource = new ExternalResource("name", "description", "id", null, null);
   resource.setEnabled(true);
   assertTrue(resource.isEnabled());
 }
  /**
   * 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());
  }