Skip to content

Commit

Permalink
test: add service reset command test case (#3552)
Browse files Browse the repository at this point in the history
* test: add service reset command test case

* test: update test case
  • Loading branch information
jsbxyyx authored and wu-sheng committed Oct 7, 2019
1 parent 47f33e6 commit e3ecf51
Showing 1 changed file with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.skywalking.api.network.trace.component.command;

import org.apache.skywalking.apm.network.common.Command;
import org.apache.skywalking.apm.network.common.KeyStringValuePair;
import org.apache.skywalking.apm.network.trace.component.command.ServiceResetCommand;
import org.junit.Assert;
import org.junit.Test;

/**
* @author jsbxyyx
*/
public class ServiceResetCommandTest {

@Test
public void serialize_Serialize_SerialNumberIsaa() throws Exception {
ServiceResetCommand command = new ServiceResetCommand("aa");
Command.Builder builder = command.serialize();

Assert.assertEquals(ServiceResetCommand.NAME, builder.getCommand());
Assert.assertEquals("aa", builder.getArgs(0).getValue());
}

@Test
public void deserialize_NullPointerException_CommandKeyIsNotSerialNumber() throws Exception {
ServiceResetCommand command = new ServiceResetCommand("aa");

Command command1 = Command.newBuilder()
.addArgs(KeyStringValuePair.newBuilder().setKey("aa").setValue("aa").build())
.build();
boolean exception = false;
try {
command.deserialize(command1);
} catch (NullPointerException e) {
exception = true;
}
Assert.assertEquals(true, exception);
}

@Test
public void deserialize_SerialNumberCompare_CommandKeyIsSerialNumberValueIsaa() throws Exception {
ServiceResetCommand command = new ServiceResetCommand("aa");

Command command2 = Command.newBuilder()
.addArgs(KeyStringValuePair.newBuilder().setKey("SerialNumber").setValue("aa").build())
.build();
ServiceResetCommand deserialize2 = command.deserialize(command2);
Assert.assertEquals("aa", deserialize2.getSerialNumber());
}

@Test
public void deserialize_SerializeAndDeserialize_SerialNumberValueIsaa() throws Exception {
ServiceResetCommand command = new ServiceResetCommand("aa");
Command.Builder builder = command.serialize();
Command command3 = builder.build();
ServiceResetCommand deserialize3 = command.deserialize(command3);
Assert.assertEquals(command.getCommand(), deserialize3.getCommand());
Assert.assertEquals(command.getSerialNumber(), deserialize3.getSerialNumber());
}

}

0 comments on commit e3ecf51

Please sign in to comment.