VagrantStrategy implements ClusterStrategy { @Override public Node createNode(Cluster cluster) throws IOException { Node node = new Node(); node.setSystemSpecification(SystemSpecification.UBUNTU_1404); node.setCluster(cluster); Path nodePath = getPath(node); if (Files.exists(nodePath)) { throw new IOException("The directory for the node to initialize already exists: " + nodePath); } Files.createDirectories(nodePath); Files.write(nodePath.resolve("Vagrantfile"), getVagrantfileContent(node).getBytes(StandardCharsets.UTF_8)); startNode(node); node.setSshConfig(getSshConfig(node)); return node; } protected  VagrantStrategy(); @Override boolean isAvailable(); @Override Node createNode(Cluster cluster); @Override NodeStatus getNodeStatus(Node node); @Override void startNode(Node node); @Override void stopNode(Node node); @Override void destroyNode(Node node); SshConfig getSshConfig(Node node); static final String NAME; }
@Test public void testInitializeNode() throws IOException { when(boxes.hasSystem(SPEC)).thenReturn(true); when(boxes.getName(SPEC)).thenReturn(BOX_NAME); Cluster cluster = mock(Cluster.class); when(cluster.getName()).thenReturn(VagrantTestData.CLUSTER_NAME); Node node = strategy.createNode(cluster); Path vagrantfilePath = vagrantPath.resolve("Vagrantfile"); assertTrue(vagrantfilePath + " does not exist", Files.exists(vagrantfilePath)); String content = FileUtils.readFileToString(vagrantfilePath.toFile()); assertThat(content, containsString("Vagrant.configure")); assertThat(content, containsString("config.vm.box = \"" + BOX_NAME + "\"")); assertThat(content, containsString("config.vm.provider \"virtualbox")); assertThat(content, containsString("v.memory = 1024")); assertThat(content, containsString("v.cpus = 2")); assertThat(content, containsString("v.name = \"" + CLUSTER_NAME + "-" + NODE_ID + "\"")); }