You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@griffin.apache.org by gu...@apache.org on 2018/06/29 14:11:25 UTC

incubator-griffin git commit: refactor dead test cases

Repository: incubator-griffin
Updated Branches:
  refs/heads/master 4cab520cf -> caa6940cc


refactor dead test cases

1.active KafkaSchemaControllerTest and resolve failures
2.trim and tidy up codes

Author: Eugene <to...@163.com>

Closes #325 from toyboxman/refactor/testcase.


Project: http://git-wip-us.apache.org/repos/asf/incubator-griffin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-griffin/commit/caa6940c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-griffin/tree/caa6940c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-griffin/diff/caa6940c

Branch: refs/heads/master
Commit: caa6940cc9f08952a96eece8749c784b3f10682a
Parents: 4cab520
Author: Eugene <to...@163.com>
Authored: Fri Jun 29 22:11:19 2018 +0800
Committer: William Guo <gu...@apache.org>
Committed: Fri Jun 29 22:11:19 2018 +0800

----------------------------------------------------------------------
 .../kafka/KafkaSchemaControllerTest.java        | 224 ++++++++++---------
 .../org/apache/griffin/core/util/URLHelper.java |   1 +
 2 files changed, 115 insertions(+), 110 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/caa6940c/service/src/test/java/org/apache/griffin/core/metastore/kafka/KafkaSchemaControllerTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/metastore/kafka/KafkaSchemaControllerTest.java b/service/src/test/java/org/apache/griffin/core/metastore/kafka/KafkaSchemaControllerTest.java
index d8328c5..42e7b05 100644
--- a/service/src/test/java/org/apache/griffin/core/metastore/kafka/KafkaSchemaControllerTest.java
+++ b/service/src/test/java/org/apache/griffin/core/metastore/kafka/KafkaSchemaControllerTest.java
@@ -1,110 +1,114 @@
-package org.apache.griffin.core.metastore.kafka;///*
-//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.griffin.core.metastore.kafka;
-//
-//import io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString;
-//import org.apache.griffin.core.metastore.kafka.KafkaSchemaController;
-//import org.apache.griffin.core.metastore.kafka.KafkaSchemaServiceImpl;
-//import org.junit.Before;
-//import org.junit.Test;
-//import org.junit.runner.RunWith;
-//import org.mockito.InjectMocks;
-//import org.mockito.Mock;
-//import org.mockito.MockitoAnnotations;
-//import org.springframework.test.context.junit4.SpringRunner;
-//import org.springframework.test.web.servlet.MockMvc;
-//import org.springframework.test.web.servlet.setup.MockMvcBuilders;
-//
-//import static org.mockito.Mockito.verify;
-//import static org.mockito.Mockito.when;
-//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
-//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
-//
-//
-//@RunWith(SpringRunner.class)
-//public class KafkaSchemaControllerTest {
-//    private MockMvc mockMvc;
-//
-//    @Mock
-//    KafkaSchemaServiceImpl kafkaSchemaService;
-//
-//    @InjectMocks
-//    private KafkaSchemaController kafkaSchemaController;
-//
-//    @Before
-//    public void setup(){
-//        MockitoAnnotations.initMocks(this);
-//        this.mockMvc = MockMvcBuilders.standaloneSetup(kafkaSchemaController).build();
-//    }
-//
-//    @Test
-//    public void test_getSubjects() throws Exception {
-//        int id=1;
-//        SchemaString ss = new SchemaString();
-//        when(kafkaSchemaService.getSchemaString(id)).thenReturn(ss);
-//        mockMvc.perform(get("/metadata/kafka/schema/{id}",id))
-//                .andExpect(status().isOk());
-//        verify(kafkaSchemaService).getSchemaString(id);
-//    }
-//
-//    @Test
-//    public void test_getSchemaString() throws Exception {
-//        when(kafkaSchemaService.getSubjects()).thenReturn(null);
-//        mockMvc.perform(get("/metadata/kafka/subject"))
-//                .andExpect(status().isOk());
-//        verify(kafkaSchemaService).getSubjects();
-//    }
-//
-//    @Test
-//    public void test_getSubjectVersions() throws Exception {
-//        String subject="sss";
-//        when(kafkaSchemaService.getSubjectVersions(subject)).thenReturn(null);
-//        mockMvc.perform(get("/metadata/kafka/subject/{subject}/version",subject))
-//                .andExpect(status().isOk());
-//        verify(kafkaSchemaService).getSubjectVersions(subject);
-//    }
-//
-//    @Test
-//    public void test_getSubjectSchema() throws Exception {
-//        String subject="ss.s";
-//        String version="ss";
-//        when(kafkaSchemaService.getSubjectSchema(subject, version)).thenReturn(null);
-//        mockMvc.perform(get("/metadata/kafka/subject/{subject}/version/{version}",subject,version))
-//                .andExpect(status().isOk());
-//        verify(kafkaSchemaService).getSubjectSchema(subject, version);
-//    }
-//
-//    @Test
-//    public void test_getTopLevelConfig() throws Exception {
-//        when(kafkaSchemaService.getTopLevelConfig()).thenReturn(null);
-//        mockMvc.perform(get("/metadata/kafka/config"))
-//                .andExpect(status().isOk());
-//        verify(kafkaSchemaService).getTopLevelConfig();
-//    }
-//
-//    @Test
-//    public void test_getSubjectLevelConfig() throws Exception {
-//        String subject="sss";
-//        when(kafkaSchemaService.getSubjectLevelConfig(subject)).thenReturn(null);
-//        mockMvc.perform(get("/metadata/kafka/config/{subject}",subject))
-//                .andExpect(status().isOk());
-//        verify(kafkaSchemaService).getSubjectLevelConfig(subject);
-//    }
-//}
+/*
+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.griffin.core.metastore.kafka;
+
+import io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString;
+import org.apache.griffin.core.util.URLHelper;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.servlet.MockMvc;
+
+import java.util.Arrays;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+
+@RunWith(SpringRunner.class)
+@WebMvcTest(value = KafkaSchemaController.class, secure = false)
+public class KafkaSchemaControllerTest {
+
+    private static final String API_PATH = URLHelper.API_VERSION_PATH + URLHelper.KAFKA_API_PATH;
+
+    @Autowired
+    private MockMvc mockMvc;
+
+    @MockBean
+    KafkaSchemaServiceImpl kafkaSchemaService;
+
+    @Before
+    public void setup() {
+        MockitoAnnotations.initMocks(this);
+    }
+
+    @Test
+    public void test_getSubjects() throws Exception {
+        int id = 1;
+        SchemaString ss = new SchemaString();
+        when(kafkaSchemaService.getSchemaString(id)).thenReturn(ss);
+        mockMvc.perform(get(API_PATH + "/schema/{id}", id))
+            .andExpect(status().isOk());
+        verify(kafkaSchemaService).getSchemaString(id);
+    }
+
+    @Test
+    public void test_getSchemaString() throws Exception {
+        when(kafkaSchemaService.getSubjects()).thenReturn(null);
+        mockMvc.perform(get(API_PATH + "/subject"))
+            .andExpect(status().isOk());
+        verify(kafkaSchemaService).getSubjects();
+    }
+
+    @Test
+    public void test_getSubjectVersions() throws Exception {
+        String subject = "s-1";
+        when(kafkaSchemaService.getSubjectVersions(subject)).thenReturn(Arrays.asList(1, 2, 3));
+        mockMvc.perform(get(API_PATH + "/versions")
+            .param("subject", subject))
+            .andExpect(status().isOk());
+        verify(kafkaSchemaService).getSubjectVersions(subject);
+    }
+
+    @Test
+    public void test_getSubjectSchema() throws Exception {
+        String subject = "ss.s";
+        String version = "ss";
+        when(kafkaSchemaService.getSubjectSchema(subject, version)).thenReturn(null);
+        mockMvc.perform(get(API_PATH + "/subjectSchema", subject, version)
+            .param("subject", subject)
+            .param("version", version))
+            .andExpect(status().isOk());
+        verify(kafkaSchemaService).getSubjectSchema(subject, version);
+    }
+
+    @Test
+    public void test_getTopLevelConfig() throws Exception {
+        when(kafkaSchemaService.getTopLevelConfig()).thenReturn(null);
+        mockMvc.perform(get(API_PATH + "/config"))
+            .andExpect(status().isOk());
+        verify(kafkaSchemaService).getTopLevelConfig();
+    }
+
+    @Test
+    public void test_getSubjectLevelConfig() throws Exception {
+        String subject = "sss";
+        when(kafkaSchemaService.getSubjectLevelConfig(subject)).thenReturn(null);
+        mockMvc.perform(get(API_PATH + "/config/{subject}", subject))
+            .andExpect(status().isOk());
+        verify(kafkaSchemaService).getSubjectLevelConfig(subject);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/caa6940c/service/src/test/java/org/apache/griffin/core/util/URLHelper.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/util/URLHelper.java b/service/src/test/java/org/apache/griffin/core/util/URLHelper.java
index 4ad4ba9..4f03998 100644
--- a/service/src/test/java/org/apache/griffin/core/util/URLHelper.java
+++ b/service/src/test/java/org/apache/griffin/core/util/URLHelper.java
@@ -21,4 +21,5 @@ package org.apache.griffin.core.util;
 
 public class URLHelper {
     public static final String API_VERSION_PATH = "/api/v1";
+    public static final String KAFKA_API_PATH = "/metadata/kafka";
 }