beiwei30 closed pull request #1949: [dubbo-1689]: Enhance the test coverage 
part-10 : dubbo-plugin module
URL: https://github.com/apache/incubator-dubbo/pull/1949
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/CommandContextFactoryTest.java
 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/CommandContextFactoryTest.java
new file mode 100644
index 0000000000..3ed31840aa
--- /dev/null
+++ 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/CommandContextFactoryTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.dubbo.qos.command;
+
+import org.hamcrest.Matchers;
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public class CommandContextFactoryTest {
+    @Test
+    public void testNewInstance() throws Exception {
+        CommandContext context = CommandContextFactory.newInstance("test");
+        assertThat(context.getCommandName(), equalTo("test"));
+        context = CommandContextFactory.newInstance("command", new 
String[]{"hello"}, true);
+        assertThat(context.getCommandName(), equalTo("command"));
+        assertThat(context.getArgs(), Matchers.arrayContaining("hello"));
+        assertTrue(context.isHttp());
+    }
+}
diff --git 
a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/CommandContextTest.java
 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/CommandContextTest.java
new file mode 100644
index 0000000000..4cc7416bf4
--- /dev/null
+++ 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/CommandContextTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.dubbo.qos.command;
+
+import io.netty.channel.Channel;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static junit.framework.TestCase.assertFalse;
+import static org.hamcrest.Matchers.arrayContaining;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public class CommandContextTest {
+    @Test
+    public void test() throws Exception {
+        CommandContext context = new CommandContext("test", new 
String[]{"hello"}, true);
+        Object request = new Object();
+        context.setOrginRequest(request);
+        Channel channel = Mockito.mock(Channel.class);
+        context.setRemote(channel);
+        assertThat(context.getCommandName(), equalTo("test"));
+        assertThat(context.getArgs(), arrayContaining("hello"));
+        assertThat(context.getOrginRequest(), is(request));
+        assertTrue(context.isHttp());
+        assertThat(context.getRemote(), is(channel));
+
+        context = new CommandContext("command");
+        context.setRemote(channel);
+        context.setOrginRequest(request);
+        context.setArgs(new String[]{"world"});
+        context.setHttp(false);
+        assertThat(context.getCommandName(), equalTo("command"));
+        assertThat(context.getArgs(), arrayContaining("world"));
+        assertThat(context.getOrginRequest(), is(request));
+        assertFalse(context.isHttp());
+        assertThat(context.getRemote(), is(channel));
+    }
+}
diff --git 
a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/DefaultCommandExecutorTest.java
 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/DefaultCommandExecutorTest.java
new file mode 100644
index 0000000000..c1c0e3f8ad
--- /dev/null
+++ 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/DefaultCommandExecutorTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.dubbo.qos.command;
+
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+public class DefaultCommandExecutorTest {
+    @Test(expected = NoSuchCommandException.class)
+    public void testExecute1() throws Exception {
+        DefaultCommandExecutor executor = new DefaultCommandExecutor();
+        executor.execute(CommandContextFactory.newInstance("not-exit"));
+    }
+
+    @Test
+    public void testExecute2() throws Exception {
+        DefaultCommandExecutor executor = new DefaultCommandExecutor();
+        String result = 
executor.execute(CommandContextFactory.newInstance("greeting", new 
String[]{"dubbo"}, false));
+        assertThat(result, equalTo("greeting dubbo"));
+    }
+}
diff --git 
a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/GreetingCommand.java
 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/GreetingCommand.java
new file mode 100644
index 0000000000..8c515ee4cb
--- /dev/null
+++ 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/GreetingCommand.java
@@ -0,0 +1,25 @@
+/*
+ * 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.dubbo.qos.command;
+
+public class GreetingCommand implements BaseCommand {
+    @Override
+    public String execute(CommandContext commandContext, String[] args) {
+        return args != null && args.length > 0 ? "greeting " + args[0] : 
"greeting";
+    }
+}
diff --git 
a/dubbo-plugin/dubbo-qos/src/test/resources/META-INF/services/org.apache.dubbo.qos.command.BaseCommand
 
b/dubbo-plugin/dubbo-qos/src/test/resources/META-INF/services/org.apache.dubbo.qos.command.BaseCommand
new file mode 100644
index 0000000000..d91f141623
--- /dev/null
+++ 
b/dubbo-plugin/dubbo-qos/src/test/resources/META-INF/services/org.apache.dubbo.qos.command.BaseCommand
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+greeting=org.apache.dubbo.qos.command.GreetingCommand
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to