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/07/03 23:50:45 UTC

incubator-griffin git commit: refactor dead test cases

Repository: incubator-griffin
Updated Branches:
  refs/heads/master 37b5cbbe1 -> ee367fb13


refactor dead test cases

1.active KafkaSchemaServiceImplTest and resolve failures

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

Closes #333 from toyboxman/testcases-1.


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

Branch: refs/heads/master
Commit: ee367fb13f799a6041dc609419fd434f1dca43a7
Parents: 37b5cbb
Author: Eugene <to...@163.com>
Authored: Wed Jul 4 07:50:24 2018 +0800
Committer: William Guo <gu...@apache.org>
Committed: Wed Jul 4 07:50:24 2018 +0800

----------------------------------------------------------------------
 .../kafka/KafkaSchemaServiceImplTest.java       | 257 ++++++++++---------
 1 file changed, 142 insertions(+), 115 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/ee367fb1/service/src/test/java/org/apache/griffin/core/metastore/kafka/KafkaSchemaServiceImplTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/metastore/kafka/KafkaSchemaServiceImplTest.java b/service/src/test/java/org/apache/griffin/core/metastore/kafka/KafkaSchemaServiceImplTest.java
index e302b8a..0d351d2 100644
--- a/service/src/test/java/org/apache/griffin/core/metastore/kafka/KafkaSchemaServiceImplTest.java
+++ b/service/src/test/java/org/apache/griffin/core/metastore/kafka/KafkaSchemaServiceImplTest.java
@@ -1,115 +1,142 @@
-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.Config;
-//import io.confluent.kafka.schemaregistry.client.rest.entities.Schema;
-//import io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString;
-//import org.junit.Before;
-//import org.junit.Test;
-//import org.junit.runner.RunWith;
-//import org.mockito.Mockito;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.boot.test.context.TestConfiguration;
-//import org.springframework.context.annotation.Bean;
-//import org.springframework.test.context.junit4.SpringRunner;
-//import org.springframework.web.client.RestTemplate;
-//
-//import static org.assertj.core.api.Assertions.fail;
-//import static org.junit.Assert.assertTrue;
-//
-//@RunWith(SpringRunner.class)
-//public class KafkaSchemaServiceImplTest {
-//    @TestConfiguration
-//    public static class KafkaSchemaServiceConfiguration {
-//        @Bean
-//        public KafkaSchemaServiceImpl service() {
-//            return new KafkaSchemaServiceImpl();
-//        }
-//    }
-//
-//    @Autowired
-//    private KafkaSchemaServiceImpl service;
-//
-//    @Before
-//    public void setup(){
-//        service.restTemplate= Mockito.mock(RestTemplate.class);
-//    }
-//
-//    @Test
-//    public void testGetSchemaString(){
-//        try {
-//            SchemaString tmp = service.getSchemaString(1);
-//            assertTrue(true);
-//        }catch (Throwable t){
-//            fail("Cannot get all tables from all dbs");
-//        }
-//    }
-//
-//    @Test
-//    public void testGetSubjects(){
-//        try {
-//            Iterable<String> tmp = service.getSubjects();
-//            assertTrue(true);
-//        }catch (Throwable t){
-//            fail("Cannot get all tables from all dbs");
-//        }
-//    }
-//
-//    @Test
-//    public void testGetSubjectVersions(){
-//        try {
-//            Iterable<Integer> tmp = service.getSubjectVersions("");
-//            assertTrue(true);
-//        }catch (Throwable t){
-//            fail("Cannot get all tables from all dbs");
-//        }
-//    }
-//
-//    @Test
-//    public void testGetSubjectSchema(){
-//        try {
-//            Schema tmp = service.getSubjectSchema("","");
-//            assertTrue(true);
-//        }catch (Throwable t){
-//            fail("Cannot get all tables from all dbs");
-//        }
-//    }
-//
-//    @Test
-//    public void testGetTopLevelConfig(){
-//        try {
-//            Config tmp = service.getTopLevelConfig();
-//            assertTrue(true);
-//        }catch (Throwable t){
-//            fail("Cannot get all tables from all dbs");
-//        }
-//    }
-//
-//    @Test
-//    public void testGetSubjectLevelConfig(){
-//        try {
-//            Config tmp = service.getSubjectLevelConfig("");
-//            assertTrue(true);
-//        }catch (Throwable t){
-//            fail("Cannot get all tables from all dbs");
-//        }
-//    }
-//}
+/*
+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.Config;
+import io.confluent.kafka.schemaregistry.client.rest.entities.Schema;
+import io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.web.client.RestTemplate;
+
+import static org.assertj.core.api.Assertions.fail;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@RunWith(SpringRunner.class)
+public class KafkaSchemaServiceImplTest {
+
+    @MockBean
+    private KafkaSchemaServiceImpl service;
+
+    @Before
+    public void setup() {
+        service.restTemplate = mock(RestTemplate.class);
+    }
+
+    @Test
+    public void testGetSchemaString() {
+        try {
+            SchemaString ss = new SchemaString();
+            ResponseEntity entity = mock(ResponseEntity.class);
+            when(service.restTemplate.getForEntity(
+                "${kafka.schema.registry.url}/schemas/ids/1",
+                SchemaString.class)).thenReturn(entity);
+            when(entity.getBody()).thenReturn(ss);
+            service.getSchemaString(1);
+            assertTrue(true);
+        } catch (Throwable t) {
+            fail("Cannot get all tables from all dbs");
+        }
+    }
+
+    @Test
+    public void testGetSubjects() {
+        try {
+            ResponseEntity entity = mock(ResponseEntity.class);
+            when(service.restTemplate.getForEntity(
+                "${kafka.schema.registry.url}/subjects",
+                String[].class)).thenReturn(entity);
+            when(entity.getBody()).thenReturn(new String[]{"aaa", "bbb"});
+            service.getSubjects();
+            assertTrue(true);
+        } catch (Throwable t) {
+            fail("Cannot get all tables from all dbs");
+        }
+    }
+
+    @Test
+    public void testGetSubjectVersions() {
+        try {
+            ResponseEntity entity = mock(ResponseEntity.class);
+            when(service.restTemplate.getForEntity(
+                "${kafka.schema.registry.url}/subjects/sub/versions",
+                Integer[].class)).thenReturn(entity);
+            when(entity.getBody()).thenReturn(new Integer[]{1, 2});
+            service.getSubjectVersions("sub");
+            assertTrue(true);
+        } catch (Throwable t) {
+            fail("Cannot get all tables from all dbs");
+        }
+    }
+
+    @Test
+    public void testGetSubjectSchema() {
+        try {
+            Schema schema = mock(Schema.class);
+            ResponseEntity entity = mock(ResponseEntity.class);
+            when(service.restTemplate.getForEntity(
+                "${kafka.schema.registry.url}/subjects/sub/versions/ver",
+                Schema.class)).thenReturn(entity);
+            when(entity.getBody()).thenReturn(schema);
+            service.getSubjectSchema("sub", "ver");
+            assertTrue(true);
+        } catch (Throwable t) {
+            fail("Cannot get all tables from all dbs");
+        }
+    }
+
+    @Test
+    public void testGetTopLevelConfig() {
+        try {
+            Config config = mock(Config.class);
+            ResponseEntity entity = mock(ResponseEntity.class);
+            when(service.restTemplate.getForEntity(
+                "${kafka.schema.registry.url}/config",
+                Config.class)).thenReturn(entity);
+            when(entity.getBody()).thenReturn(config);
+            service.getTopLevelConfig();
+            assertTrue(true);
+        } catch (Throwable t) {
+            fail("Cannot get all tables from all dbs");
+        }
+    }
+
+    @Test
+    public void testGetSubjectLevelConfig() {
+        try {
+            Config config = mock(Config.class);
+            ResponseEntity entity = mock(ResponseEntity.class);
+            when(service.restTemplate.getForEntity(
+                "${kafka.schema.registry.url}/config/subject",
+                Config.class)).thenReturn(entity);
+            when(entity.getBody()).thenReturn(config);
+            service.getSubjectLevelConfig("subject");
+            assertTrue(true);
+        } catch (Throwable t) {
+            fail("Cannot get all tables from all dbs");
+        }
+    }
+}