/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2010, Red Hat, Inc., and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.as.server.manager;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertSame;
import static junit.framework.Assert.fail;

import org.jboss.as.server.manager.ServerManagerProtocol.Command;
import org.jboss.as.server.manager.ServerManagerProtocol.ServerManagerToServerProtocolCommand;
import org.junit.Test;

/**
 *
 * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
 * @version $Revision: 1.1 $
 */
public class ServerManagerProtocolCommandUnitTestCase {

    @Test
    public void testSmStop() throws Exception {
        byte[] bytes = ServerManagerToServerProtocolCommand.STOP_SERVER.createCommandBytes(null);
        Command<ServerManagerToServerProtocolCommand> stop = ServerManagerToServerProtocolCommand.readCommand(bytes);
        assertSame(ServerManagerToServerProtocolCommand.STOP_SERVER, stop.getCommand());
        assertEquals(0, stop.getData().length);
    }

    @Test
    public void testSmStart() throws Exception {
        byte[] data = new byte[] {10, 11, 12, 13, 14, 15};
        byte[] bytes = ServerManagerToServerProtocolCommand.START_SERVER.createCommandBytes(data);
        Command<ServerManagerToServerProtocolCommand> start = ServerManagerToServerProtocolCommand.readCommand(bytes);
        assertSame(ServerManagerToServerProtocolCommand.START_SERVER, start.getCommand());

        assertEquals(data.length, start.getData().length);
        for (int i = 0 ; i < data.length ; i++)
            assertEquals(data[i], start.getData()[i]);
    }

    @Test
    public void testFailNoArgsCommandWithData() throws Exception {
        try {
            byte[] data = new byte[] {5, 6, 7};
            ServerManagerToServerProtocolCommand.STOP_SERVER.createCommandBytes(data);
        }catch (Exception ignore) {
            return;
        }
        fail("Should have picked up not expected data");
    }

    @Test
    public void testFailArgsCommandWithNoData() throws Exception {
        try {
            ServerManagerToServerProtocolCommand.START_SERVER.createCommandBytes(null);
        }catch (Exception ignore) {
            return;
        }
        fail("Should have picked up missing data");
    }

    @Test
    public void testParseServerManagerProtocolCommands() {
        for (ServerManagerToServerProtocolCommand cmd : ServerManagerToServerProtocolCommand.values()) {
            byte b = cmd.getId();
            assertEquals(cmd, ServerManagerToServerProtocolCommand.parse(b));
        }
    }
}

@@ -1198,16 +1198,46 @@
 .fail;%0A%0A
+import java.util.Collections;%0A
 import o
@@ -1286,32 +1286,32 @@
 otocol.Command;%0A
-
 import org.jboss
@@ -1989,605 +1989,8 @@
  %7D%0A%0A
-    @Test%0A    public void testSmStart() throws Exception %7B%0A        byte%5B%5D data = new byte%5B%5D %7B10, 11, 12, 13, 14, 15%7D;%0A        byte%5B%5D bytes = ServerManagerToServerProtocolCommand.START_SERVER.createCommandBytes(data);%0A        Command%3CServerManagerToServerProtocolCommand%3E start = ServerManagerToServerProtocolCommand.readCommand(bytes);%0A        assertSame(ServerManagerToServerProtocolCommand.START_SERVER, start.getCommand());%0A%0A        assertEquals(data.length, start.getData().length);%0A        for (int i = 0 ; i %3C data.length ; i++)%0A            assertEquals(data%5Bi%5D, start.getData()%5Bi%5D);%0A    %7D%0A%0A
     
@@ -2770,16 +2770,38 @@
 d cmd : 
+Collections.singleton(
 ServerMa
@@ -2833,15 +2833,19 @@
 and.
-values(
+STOP_SERVER
 )) %7B

Fix unit test to only test things that are being used