pareshddevalia commented on code in PR #419: URL: https://github.com/apache/atlas/pull/419#discussion_r2253785487
########## addons/impala-bridge/src/test/java/org/apache/atlas/impala/hook/events/CreateImpalaProcessTest.java: ########## @@ -0,0 +1,317 @@ +package org.apache.atlas.impala.hook.events; + +/** 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. + **/ + +import org.apache.atlas.impala.hook.AtlasImpalaHookContext; +import org.apache.atlas.impala.hook.ImpalaLineageHook; +import org.apache.atlas.impala.model.ImpalaDependencyType; +import org.apache.atlas.impala.model.ImpalaOperationType; +import org.apache.atlas.impala.model.ImpalaQuery; +import org.apache.atlas.impala.model.ImpalaVertexType; +import org.apache.atlas.impala.model.LineageEdge; +import org.apache.atlas.impala.model.LineageVertex; +import org.apache.atlas.impala.model.LineageVertexMetadata; +import org.apache.atlas.model.instance.AtlasEntity; +import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo; +import org.apache.atlas.model.notification.HookNotification; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.apache.atlas.impala.hook.events.BaseImpalaEvent.ATTRIBUTE_NAME; +import static org.apache.atlas.impala.hook.events.BaseImpalaEvent.ATTRIBUTE_QUALIFIED_NAME; +import static org.mockito.Mockito.when; +import static org.testng.Assert.*; + +public class CreateImpalaProcessTest { + private static final Logger LOG = LoggerFactory.getLogger(CreateImpalaProcessTest.class); + + @Mock + private ImpalaLineageHook mockHook; + + @Mock + private AtlasImpalaHookContext mockContext; + + @Mock + private ImpalaLineageHook impalaLineageHook; + + @Mock + private ImpalaOperationType impalaOperationType; + + @Mock + private ImpalaQuery impalaQuery; + + + private CreateImpalaProcess createImpalaProcess; + + private static final String CLUSTER_NAME = "testcluster"; + private static final String DB_NAME = "testdb"; + private static final String TABLE_NAME_SOURCE = "source_table"; + private static final String TABLE_NAME_TARGET = "target_table"; + private static final String COLUMN_NAME_ID = "id"; + private static final String COLUMN_NAME_NAME = "name"; + private static final String USER_NAME = "testuser"; + private static final String HOST_NAME = "testhost"; + private static final String QUERY_TEXT = "CREATE VIEW target_table AS SELECT id, name FROM source_db.source_table"; + private static final String QUERY_ID = "test_query_id_123"; + private static final long TIMESTAMP = 1554750072L; + private static final long END_TIME = 1554750554L; + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + + when(mockHook.getMetadataNamespace()).thenReturn(CLUSTER_NAME); + when(mockHook.getHostName()).thenReturn(HOST_NAME); + when(mockHook.isConvertHdfsPathToLowerCase()).thenReturn(false); + + when(mockContext.getUserName()).thenReturn(USER_NAME); + when(mockContext.getHostName()).thenReturn(HOST_NAME); + when(mockContext.getMetadataNamespace()).thenReturn(CLUSTER_NAME); + when(mockContext.getQueryStr()).thenReturn(QUERY_TEXT); + when(mockContext.getImpalaOperationType()).thenReturn(ImpalaOperationType.CREATEVIEW); + + createImpalaProcess = new CreateImpalaProcess(mockContext); + } + + + @Test + public void testGetNotificationMessagesWithNoEntities() throws Exception { + + ImpalaQuery emptyQuery = new ImpalaQuery(); + emptyQuery.setVertices(new ArrayList<>()); + emptyQuery.setEdges(new ArrayList<>()); + emptyQuery.setQueryText(QUERY_TEXT); + emptyQuery.setQueryId(QUERY_ID); + emptyQuery.setUser(USER_NAME); + emptyQuery.setTimestamp(TIMESTAMP); + emptyQuery.setEndTime(END_TIME); + + when(mockContext.getLineageQuery()).thenReturn(emptyQuery); + + CreateImpalaProcess process = new CreateImpalaProcess(mockContext); + List<HookNotification> notifications = process.getNotificationMessages(); + + assertNull(notifications); + } + + + @Test + public void testGetEntitiesWithValidData() throws Exception { + ImpalaQuery query = createTestQuery(); + when(mockContext.getLineageQuery()).thenReturn(query); + + AtlasEntity mockInputEntity = createMockTableEntity(TABLE_NAME_SOURCE); + AtlasEntity mockOutputEntity = createMockTableEntity(TABLE_NAME_TARGET); + + when(mockContext.getEntity(getQualifiedTableName(TABLE_NAME_SOURCE))) + .thenReturn(mockInputEntity); + when(mockContext.getEntity(getQualifiedTableName(TABLE_NAME_TARGET))) + .thenReturn(mockOutputEntity); + + CreateImpalaProcess process = new CreateImpalaProcess(mockContext); + AtlasEntitiesWithExtInfo entities = process.getEntities(); Review Comment: You are not asserting anything about the result. Try to add test-case coverage upto 95% -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@atlas.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org