@Test public void test() { ChefApi chef = createMock(ChefApi.class); Map<String, JsonBall> automatic = ImmutableMap.<String, JsonBall> of(); Supplier<Map<String, JsonBall>> automaticSupplier = Suppliers.<Map<String, JsonBall>> ofInstance(automatic); Node node = Node.builder().name("name").environment("_default").build(); Node nodeWithAutomatic = Node.builder().name("name").environment("_default").automaticAttributes(automatic) .build(); expect(chef.getNode("name")).andReturn(node); expect(chef.updateNode(nodeWithAutomatic)).andReturn(null); replay(chef); UpdateAutomaticAttributesOnNodeImpl updater = new UpdateAutomaticAttributesOnNodeImpl(chef, automaticSupplier); updater.execute("name"); verify(chef); }
@Override public void execute(String nodeName) { logger.trace("updating node %s", nodeName); Node node = chef.getNode(nodeName); Node updated = Node.builder() .name(node.getName()) .normalAttributes(node.getNormalAttributes()) .overrideAttributes(node.getOverrideAttributes()) .defaultAttributes(node.getDefaultAttributes()) .automaticAttributes(automaticSupplier.get()) .runList(node.getRunList()) .environment(node.getEnvironment()) .build(); chef.updateNode(updated); logger.debug("updated node %s", nodeName); }
UpdateAutomaticAttributesOnNodeImpl implements UpdateAutomaticAttributesOnNode { @Override public void execute(String nodeName) { logger.trace("updating node %s", nodeName); Node node = chef.getNode(nodeName); Node updated = Node.builder() .name(node.getName()) .normalAttributes(node.getNormalAttributes()) .overrideAttributes(node.getOverrideAttributes()) .defaultAttributes(node.getDefaultAttributes()) .automaticAttributes(automaticSupplier.get()) .runList(node.getRunList()) .environment(node.getEnvironment()) .build(); chef.updateNode(updated); logger.debug("updated node %s", nodeName); } }
UpdateAutomaticAttributesOnNodeImpl implements UpdateAutomaticAttributesOnNode { @Override public void execute(String nodeName) { logger.trace("updating node %s", nodeName); Node node = chef.getNode(nodeName); Node updated = Node.builder() .name(node.getName()) .normalAttributes(node.getNormalAttributes()) .overrideAttributes(node.getOverrideAttributes()) .defaultAttributes(node.getDefaultAttributes()) .automaticAttributes(automaticSupplier.get()) .runList(node.getRunList()) .environment(node.getEnvironment()) .build(); chef.updateNode(updated); logger.debug("updated node %s", nodeName); } @Inject  UpdateAutomaticAttributesOnNodeImpl(ChefApi chef, @Automatic Supplier<Map<String, JsonBall>> automaticSupplier); }
UpdateAutomaticAttributesOnNodeImpl implements UpdateAutomaticAttributesOnNode { @Override public void execute(String nodeName) { logger.trace("updating node %s", nodeName); Node node = chef.getNode(nodeName); Node updated = Node.builder() .name(node.getName()) .normalAttributes(node.getNormalAttributes()) .overrideAttributes(node.getOverrideAttributes()) .defaultAttributes(node.getDefaultAttributes()) .automaticAttributes(automaticSupplier.get()) .runList(node.getRunList()) .environment(node.getEnvironment()) .build(); chef.updateNode(updated); logger.debug("updated node %s", nodeName); } @Inject  UpdateAutomaticAttributesOnNodeImpl(ChefApi chef, @Automatic Supplier<Map<String, JsonBall>> automaticSupplier); @Override void execute(String nodeName); }
UpdateAutomaticAttributesOnNodeImpl implements UpdateAutomaticAttributesOnNode { @Override public void execute(String nodeName) { logger.trace("updating node %s", nodeName); Node node = chef.getNode(nodeName); Node updated = Node.builder() .name(node.getName()) .normalAttributes(node.getNormalAttributes()) .overrideAttributes(node.getOverrideAttributes()) .defaultAttributes(node.getDefaultAttributes()) .automaticAttributes(automaticSupplier.get()) .runList(node.getRunList()) .environment(node.getEnvironment()) .build(); chef.updateNode(updated); logger.debug("updated node %s", nodeName); } @Inject  UpdateAutomaticAttributesOnNodeImpl(ChefApi chef, @Automatic Supplier<Map<String, JsonBall>> automaticSupplier); @Override void execute(String nodeName);  }