Package com.netflix.genie.common.model

Examples of com.netflix.genie.common.model.Command


        Mockito.when(this.response.isSuccess()).thenReturn(true);

        final List<Command> commands = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            commands.add(
                    new Command(
                            "name" + i,
                            "user" + i,
                            CommandStatus.ACTIVE,
                            "executable" + i,
                            "" + i
                    )
            );
        }

        final ObjectMapper mapper = new ObjectMapper();
        final StringWriter writer = new StringWriter();
        mapper.writeValue(writer, commands);
        final String inputEntity = writer.toString();
        final InputStream is = new ByteArrayInputStream(inputEntity.getBytes(Charset.forName("UTF-8")));
        Mockito.when(this.response.getInputStream()).thenReturn(is);
        Mockito.when(this.restClient.executeWithLoadBalancer(this.request)).thenReturn(this.response);

        @SuppressWarnings("unchecked")
        final List<Command> outputCommands = (List<Command>) this.client.executeRequest(
                this.request, List.class, Command.class);

        Assert.assertEquals(commands.size(), outputCommands.size());
        for (int i = 0; i < commands.size(); i++) {
            final Command expected = commands.get(i);
            final Command actual = outputCommands.get(i);
            Assert.assertEquals(expected.getName(), actual.getName());
            Assert.assertEquals(expected.getUser(), actual.getUser());
            Assert.assertEquals(expected.getStatus(), actual.getStatus());
            Assert.assertEquals(expected.getExecutable(), actual.getExecutable());
            Assert.assertEquals(expected.getVersion(), actual.getVersion());
        }

        Mockito.verify(this.response, Mockito.times(1)).isSuccess();
        Mockito.verify(this.response, Mockito.times(1)).getInputStream();
    }
View Full Code Here


     *
     * @throws GenieException
     */
    @Test
    public void testGetCommand() throws GenieException {
        final Command command1 = this.service.getCommand(COMMAND_1_ID);
        Assert.assertEquals(COMMAND_1_ID, command1.getId());
        Assert.assertEquals(COMMAND_1_NAME, command1.getName());
        Assert.assertEquals(COMMAND_1_USER, command1.getUser());
        Assert.assertEquals(COMMAND_1_VERSION, command1.getVersion());
        Assert.assertEquals(COMMAND_1_STATUS, command1.getStatus());
        Assert.assertEquals(COMMAND_1_EXECUTABLE, command1.getExecutable());
        Assert.assertEquals(COMMAND_1_JOB_TYPE, command1.getJobType());
        Assert.assertNotNull(command1.getApplication());
        Assert.assertEquals(APP_1_ID, command1.getApplication().getId());
        Assert.assertEquals(5, command1.getTags().size());
        Assert.assertEquals(2, command1.getConfigs().size());

        final Command command2 = this.service.getCommand(COMMAND_2_ID);
        Assert.assertEquals(COMMAND_2_ID, command2.getId());
        Assert.assertEquals(COMMAND_2_NAME, command2.getName());
        Assert.assertEquals(COMMAND_2_USER, command2.getUser());
        Assert.assertEquals(COMMAND_2_VERSION, command2.getVersion());
        Assert.assertEquals(COMMAND_2_STATUS, command2.getStatus());
        Assert.assertEquals(COMMAND_2_EXECUTABLE, command2.getExecutable());
        Assert.assertEquals(COMMAND_2_JOB_TYPE, command2.getJobType());
        Assert.assertNull(command2.getApplication());
        Assert.assertEquals(4, command2.getTags().size());
        Assert.assertEquals(1, command2.getConfigs().size());

        final Command command3 = this.service.getCommand(COMMAND_3_ID);
        Assert.assertEquals(COMMAND_3_ID, command3.getId());
        Assert.assertEquals(COMMAND_3_NAME, command3.getName());
        Assert.assertEquals(COMMAND_3_USER, command3.getUser());
        Assert.assertEquals(COMMAND_3_VERSION, command3.getVersion());
        Assert.assertEquals(COMMAND_3_STATUS, command3.getStatus());
        Assert.assertEquals(COMMAND_3_EXECUTABLE, command3.getExecutable());
        Assert.assertEquals(COMMAND_3_JOB_TYPE, command3.getJobType());
        Assert.assertNull(command3.getApplication());
        Assert.assertEquals(5, command3.getTags().size());
        Assert.assertEquals(1, command3.getConfigs().size());
    }
View Full Code Here

     *
     * @throws GenieException
     */
    @Test
    public void testCreateCommand() throws GenieException {
        final Command command = new Command(
                COMMAND_1_NAME,
                COMMAND_1_USER,
                CommandStatus.ACTIVE,
                COMMAND_1_EXECUTABLE,
                COMMAND_1_VERSION
        );
        final String id = UUID.randomUUID().toString();
        command.setId(id);
        final Command created = this.service.createCommand(command);
        Assert.assertNotNull(this.service.getCommand(id));
        Assert.assertEquals(id, created.getId());
        Assert.assertEquals(COMMAND_1_NAME, created.getName());
        Assert.assertEquals(COMMAND_1_USER, created.getUser());
        Assert.assertEquals(CommandStatus.ACTIVE, created.getStatus());
        Assert.assertEquals(COMMAND_1_EXECUTABLE, created.getExecutable());
        this.service.deleteCommand(id);
        try {
            this.service.getCommand(id);
            Assert.fail("Should have thrown exception");
        } catch (final GenieException ge) {
View Full Code Here

     *
     * @throws GenieException
     */
    @Test
    public void testCreateCommandNoId() throws GenieException {
        final Command command = new Command(
                COMMAND_1_NAME,
                COMMAND_1_USER,
                CommandStatus.ACTIVE,
                COMMAND_1_EXECUTABLE,
                COMMAND_1_VERSION
        );
        final Command created = this.service.createCommand(command);
        Assert.assertNotNull(this.service.getCommand(created.getId()));
        Assert.assertEquals(COMMAND_1_NAME, created.getName());
        Assert.assertEquals(COMMAND_1_USER, created.getUser());
        Assert.assertEquals(CommandStatus.ACTIVE, created.getStatus());
        Assert.assertEquals(COMMAND_1_EXECUTABLE, created.getExecutable());
        this.service.deleteCommand(created.getId());
        try {
            this.service.getCommand(created.getId());
            Assert.fail("Should have thrown exception");
        } catch (final GenieException ge) {
            Assert.assertEquals(
                    HttpURLConnection.HTTP_NOT_FOUND,
                    ge.getErrorCode()
View Full Code Here

     *
     * @throws GenieException
     */
    @Test(expected = GenieConflictException.class)
    public void testCreateCommandAlreadyExists() throws GenieException {
        final Command command = new Command(
                COMMAND_1_NAME,
                COMMAND_1_USER,
                CommandStatus.ACTIVE,
                COMMAND_1_EXECUTABLE,
                COMMAND_1_VERSION
        );
        command.setId(COMMAND_1_ID);
        this.service.createCommand(command);
    }
View Full Code Here

     *
     * @throws GenieException
     */
    @Test
    public void testUpdateCommandNoId() throws GenieException {
        final Command init = this.service.getCommand(COMMAND_1_ID);
        Assert.assertEquals(COMMAND_1_USER, init.getUser());
        Assert.assertEquals(CommandStatus.ACTIVE, init.getStatus());
        Assert.assertEquals(5, init.getTags().size());

        final Command updateCommand = new Command();
        updateCommand.setStatus(CommandStatus.INACTIVE);
        updateCommand.setUser(COMMAND_2_USER);
        final Set<String> tags = new HashSet<>();
        tags.add("prod");
        tags.add("tez");
        tags.add("yarn");
        tags.add("hadoop");
        updateCommand.setTags(tags);
        this.service.updateCommand(COMMAND_1_ID, updateCommand);

        final Command updated = this.service.getCommand(COMMAND_1_ID);
        Assert.assertEquals(COMMAND_2_USER, updated.getUser());
        Assert.assertEquals(CommandStatus.INACTIVE, updated.getStatus());
        Assert.assertEquals(6, updated.getTags().size());
    }
View Full Code Here

     *
     * @throws GenieException
     */
    @Test
    public void testUpdateCommandWithId() throws GenieException {
        final Command init = this.service.getCommand(COMMAND_1_ID);
        Assert.assertEquals(COMMAND_1_USER, init.getUser());
        Assert.assertEquals(CommandStatus.ACTIVE, init.getStatus());
        Assert.assertEquals(5, init.getTags().size());

        final Command updateApp = new Command();
        updateApp.setId(COMMAND_1_ID);
        updateApp.setStatus(CommandStatus.INACTIVE);
        updateApp.setUser(COMMAND_2_USER);
        final Set<String> tags = new HashSet<>();
        tags.add("prod");
        tags.add("tez");
        tags.add("yarn");
        tags.add("hadoop");
        updateApp.setTags(tags);
        this.service.updateCommand(COMMAND_1_ID, updateApp);

        final Command updated = this.service.getCommand(COMMAND_1_ID);
        Assert.assertEquals(COMMAND_2_USER, updated.getUser());
        Assert.assertEquals(CommandStatus.INACTIVE, updated.getStatus());
        Assert.assertEquals(6, updated.getTags().size());
    }
View Full Code Here

     *
     * @throws GenieException
     */
    @Test(expected = GeniePreconditionException.class)
    public void testUpdateCommandNullId() throws GenieException {
        this.service.updateCommand(null, new Command());
    }
View Full Code Here

     * @throws GenieException
     */
    @Test(expected = GenieNotFoundException.class)
    public void testUpdateCommandNoCommandExists() throws GenieException {
        this.service.updateCommand(
                UUID.randomUUID().toString(), new Command());
    }
View Full Code Here

     *
     * @throws GenieException
     */
    @Test(expected = GenieBadRequestException.class)
    public void testUpdateCommandIdsDontMatch() throws GenieException {
        final Command updateApp = new Command();
        updateApp.setId(UUID.randomUUID().toString());
        this.service.updateCommand(COMMAND_1_ID, updateApp);
    }
View Full Code Here

TOP

Related Classes of com.netflix.genie.common.model.Command

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.