Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Open Subsurface Data Universe Software
Platform
Data Flow
Data Ingestion
Ingestion Workflow
Commits
018d5fc8
Commit
018d5fc8
authored
Aug 04, 2020
by
satish kumar nargani
Committed by
Pingjiang Wang
Aug 04, 2020
Browse files
Junit Test Cases for Workflow Service
parent
57e73306
Changes
5
Hide whitespace changes
Inline
Side-by-side
provider/workflow-azure/pom.xml
View file @
018d5fc8
...
@@ -24,12 +24,12 @@
...
@@ -24,12 +24,12 @@
<relativePath>
../../pom.xml
</relativePath>
<relativePath>
../../pom.xml
</relativePath>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
workflow-azure
</artifactId>
<artifactId>
workflow-azure
</artifactId>
<description>
Workflow service on Azure
</description>
<description>
Workflow service on Azure
</description>
<packaging>
jar
</packaging>
<packaging>
jar
</packaging>
<properties>
<properties>
<azure.version>
2.1.7
</azure.version>
<azure.version>
2.1.7
</azure.version>
<osdu.azurecore.version>
0.0.6-SNAPSHOT
</osdu.azurecore.version>
<osdu.azurecore.version>
0.0.6-SNAPSHOT
</osdu.azurecore.version>
<azure.appservice.resourcegroup></azure.appservice.resourcegroup>
<azure.appservice.resourcegroup></azure.appservice.resourcegroup>
...
@@ -83,8 +83,8 @@
...
@@ -83,8 +83,8 @@
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.mockito
</groupId>
<groupId>
org.mockito
</groupId>
<artifactId>
mockito-
all
</artifactId>
<artifactId>
mockito-
core
</artifactId>
<version>
1.10.19
</version>
<version>
3.4.4
</version>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<dependency>
...
@@ -126,27 +126,27 @@
...
@@ -126,27 +126,27 @@
<url>
https://community.opengroup.org/api/v4/projects/44/packages/maven
</url>
<url>
https://community.opengroup.org/api/v4/projects/44/packages/maven
</url>
</snapshotRepository>
</snapshotRepository>
</distributionManagement>
</distributionManagement>
<build>
<build>
<plugins>
<plugins>
<plugin>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<executions>
<executions>
<execution>
<execution>
<goals>
<goals>
<goal>
repackage
</goal>
<goal>
repackage
</goal>
</goals>
</goals>
<configuration>
<configuration>
<classifier>
spring-boot
</classifier>
<classifier>
spring-boot
</classifier>
<mainClass>
org.opengroup.osdu.workflow.provider.azure.WorkflowApplication
</mainClass>
<mainClass>
org.opengroup.osdu.workflow.provider.azure.WorkflowApplication
</mainClass>
</configuration>
</configuration>
</execution>
</execution>
</executions>
</executions>
</plugin>
</plugin>
<plugin>
<plugin>
<groupId>
com.microsoft.azure
</groupId>
<groupId>
com.microsoft.azure
</groupId>
<artifactId>
azure-webapp-maven-plugin
</artifactId>
<artifactId>
azure-webapp-maven-plugin
</artifactId>
<version>
1.7.0
</version>
<version>
1.7.0
</version>
<configuration>
<configuration>
<schemaVersion>
V2
</schemaVersion>
<schemaVersion>
V2
</schemaVersion>
<authentication>
<authentication>
...
@@ -175,5 +175,5 @@
...
@@ -175,5 +175,5 @@
</configuration>
</configuration>
</plugin>
</plugin>
</plugins>
</plugins>
</build>
</build>
</project>
</project>
provider/workflow-azure/src/test/java/org/opengroup/osdu/workflow/provider/azure/repository/IngestionStrategyRepositoryTest.java
0 → 100644
View file @
018d5fc8
package
org.opengroup.osdu.workflow.provider.azure.repository
;
import
com.azure.cosmos.*
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
org.opengroup.osdu.core.common.model.WorkflowType
;
import
org.opengroup.osdu.core.common.model.http.AppException
;
import
org.opengroup.osdu.workflow.model.IngestionStrategy
;
import
org.opengroup.osdu.workflow.provider.azure.WorkflowApplication
;
import
org.opengroup.osdu.workflow.provider.azure.model.IngestionStrategyDoc
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
static
org
.
mockito
.
Mockito
.
doThrow
;
import
javax.inject.Named
;
import
java.io.IOException
;
@RunWith
(
MockitoJUnitRunner
.
class
)
@SpringBootTest
(
classes
=
{
WorkflowApplication
.
class
})
public
class
IngestionStrategyRepositoryTest
{
@Mock
private
CosmosItem
cosmosItem
;
@Mock
private
CosmosItemResponse
cosmosResponse
;
@Mock
private
CosmosItemProperties
cosmosItemProperties
;
@Mock
@Named
(
"INGESTION_STRATEGY_CONTAINER"
)
private
CosmosContainer
ingestionStrategyContainer
;
@InjectMocks
private
IngestionStrategyRepository
repository
;
@Before
public
void
initMocks
()
throws
Exception
{
doReturn
(
cosmosItem
).
when
(
ingestionStrategyContainer
).
getItem
(
any
(),
any
());
doReturn
(
cosmosResponse
).
when
(
cosmosItem
).
read
(
any
());
doReturn
(
cosmosItemProperties
).
when
(
cosmosResponse
).
getProperties
();
}
@Test
public
void
findByWorkflowTypeAndDataTypeAndUserId
()
throws
CosmosClientException
,
IOException
{
IngestionStrategyDoc
ingestionStrategyDoc
=
new
IngestionStrategyDoc
();
ingestionStrategyDoc
.
setDagName
(
"osdu_python_sdk_well_log_ingestion"
);
ingestionStrategyDoc
.
setDataType
(
"well_log"
);
ingestionStrategyDoc
.
setWorkflowType
(
WorkflowType
.
OSDU
.
name
());
doReturn
(
ingestionStrategyDoc
)
.
when
(
cosmosItemProperties
)
.
getObject
(
any
());
IngestionStrategy
ingestionStrategy
=
repository
.
findByWorkflowTypeAndDataTypeAndUserId
(
WorkflowType
.
OSDU
,
"well_log"
,
""
);
Assert
.
assertNotNull
(
ingestionStrategy
);
Assert
.
assertEquals
(
getIngestionStrategy
().
getDagName
(),
ingestionStrategy
.
getDagName
());
Assert
.
assertEquals
(
getIngestionStrategy
().
getDataType
(),
ingestionStrategy
.
getDataType
());
Assert
.
assertEquals
(
getIngestionStrategy
().
getWorkflowType
(),
ingestionStrategy
.
getWorkflowType
());
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
shouldThrowExceptionWhenRecordNotFound
()
throws
CosmosClientException
{
doThrow
(
NullPointerException
.
class
)
.
when
(
cosmosItem
)
.
read
(
any
());
repository
.
findByWorkflowTypeAndDataTypeAndUserId
(
WorkflowType
.
OSDU
,
"test"
,
""
);
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
shouldThrowExceptionWhenDataTypeAndWorkflowTypeNotFound
()
throws
Throwable
{
doThrow
(
NotFoundException
.
class
)
.
when
(
cosmosItem
)
.
read
(
any
());
repository
.
findByWorkflowTypeAndDataTypeAndUserId
(
WorkflowType
.
OSDU
,
"well_log111"
,
"opendes11"
);
Assert
.
assertFalse
(
throwException
());
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
shouldThrowExceptionWhenDocumentisMalformed
()
throws
IOException
{
doThrow
(
IOException
.
class
)
.
when
(
cosmosItemProperties
)
.
getObject
(
any
());
repository
.
findByWorkflowTypeAndDataTypeAndUserId
(
WorkflowType
.
OSDU
,
"well_log111"
,
"opendes11"
);
Assert
.
assertFalse
(
throwException
());
}
@Test
(
expected
=
AppException
.
class
)
public
void
shouldThrowExceptionWhenCosmosException
()
throws
CosmosClientException
{
doThrow
(
CosmosClientException
.
class
)
.
when
(
cosmosItem
)
.
read
(
any
());
repository
.
findByWorkflowTypeAndDataTypeAndUserId
(
WorkflowType
.
INGEST
,
"well_log"
,
""
);
}
private
IngestionStrategy
getIngestionStrategy
()
{
return
IngestionStrategy
.
builder
()
.
workflowType
(
WorkflowType
.
OSDU
)
.
dataType
(
"well_log"
)
.
userId
(
""
)
.
dagName
(
"osdu_python_sdk_well_log_ingestion"
)
.
build
();
}
private
boolean
throwException
()
{
throw
new
NullPointerException
();
}
}
provider/workflow-azure/src/test/java/org/opengroup/osdu/workflow/provider/azure/repository/WorkflowStatusRepositoryTest.java
0 → 100644
View file @
018d5fc8
package
org.opengroup.osdu.workflow.provider.azure.repository
;
import
com.azure.cosmos.*
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
org.opengroup.osdu.core.common.model.http.AppException
;
import
org.opengroup.osdu.workflow.exception.WorkflowNotFoundException
;
import
org.opengroup.osdu.workflow.model.WorkflowStatus
;
import
org.opengroup.osdu.workflow.model.WorkflowStatusType
;
import
org.opengroup.osdu.workflow.provider.azure.WorkflowApplication
;
import
org.opengroup.osdu.workflow.provider.azure.model.WorkflowStatusDoc
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
static
org
.
mockito
.
Mockito
.
doThrow
;
import
javax.inject.Named
;
import
java.io.IOException
;
@RunWith
(
MockitoJUnitRunner
.
class
)
@SpringBootTest
(
classes
=
{
WorkflowApplication
.
class
})
public
class
WorkflowStatusRepositoryTest
{
private
static
final
String
TEST_WORKFLOW_ID
=
"test-workflow-id"
;
private
static
final
String
TEST_AIRFLOW_RUN_ID
=
"test-airflow-run-id"
;
@Mock
private
CosmosItem
cosmosItem
;
@Mock
private
CosmosItemResponse
cosmosResponse
;
@Mock
private
CosmosItemProperties
cosmosItemProperties
;
@Mock
@Named
(
"WORKFLOW_STATUS_CONTAINER"
)
private
CosmosContainer
workflowStatusContainer
;
@InjectMocks
private
WorkflowStatusRepository
workflowStatusRepository
;
@Before
public
void
initMocks
()
throws
Exception
{
doReturn
(
cosmosItem
).
when
(
workflowStatusContainer
).
getItem
(
any
(),
any
());
doReturn
(
cosmosResponse
).
when
(
cosmosItem
).
read
(
any
());
doReturn
(
cosmosItemProperties
).
when
(
cosmosResponse
).
getProperties
();
}
@Test
public
void
shouldFindWorkflowStatusByWorkflowId
()
throws
IOException
{
WorkflowStatusDoc
workflowStatusDoc
=
createWorkflowStatusDocWithStatusFinished
();
doReturn
(
workflowStatusDoc
)
.
when
(
cosmosItemProperties
)
.
getObject
(
any
());
WorkflowStatus
workflowStatus
=
workflowStatusRepository
.
findWorkflowStatus
(
"TestWorkflowId"
);
Assert
.
assertNotNull
(
workflowStatus
);
Assert
.
assertEquals
(
getWorkflowStatus
().
getAirflowRunId
(),
workflowStatusDoc
.
getAirflowRunId
());
Assert
.
assertEquals
(
getWorkflowStatus
().
getWorkflowId
(),
workflowStatusDoc
.
getWorkflowId
());
}
@Test
(
expected
=
WorkflowNotFoundException
.
class
)
public
void
shouldThrowExceptionWhenWorkflowNotFound
()
throws
CosmosClientException
{
doThrow
(
NotFoundException
.
class
)
.
when
(
cosmosItem
)
.
read
(
any
());
workflowStatusRepository
.
findWorkflowStatus
(
"InvalidWorkflowId"
);
}
@Test
(
expected
=
AppException
.
class
)
public
void
shouldThrowExceptionWhenCosmosException
()
throws
CosmosClientException
{
doThrow
(
CosmosClientException
.
class
)
.
when
(
cosmosItem
)
.
read
(
any
());
workflowStatusRepository
.
findWorkflowStatus
(
TEST_WORKFLOW_ID
);
}
private
WorkflowStatus
getWorkflowStatus
()
{
return
WorkflowStatus
.
builder
()
.
airflowRunId
(
TEST_AIRFLOW_RUN_ID
)
.
workflowId
(
TEST_WORKFLOW_ID
)
.
workflowStatusType
(
WorkflowStatusType
.
FINISHED
)
.
build
();
}
@Test
public
void
saveWorkflowStatusAndReturnExistingCollection
()
throws
IOException
{
WorkflowStatus
workflowstatus
=
WorkflowStatus
.
builder
()
.
workflowId
(
TEST_WORKFLOW_ID
)
.
airflowRunId
(
TEST_AIRFLOW_RUN_ID
)
.
workflowStatusType
(
WorkflowStatusType
.
FINISHED
)
.
build
();
doReturn
(
createWorkflowStatusDocWithStatusFinished
())
.
when
(
cosmosItemProperties
)
.
getObject
(
any
());
WorkflowStatus
status
=
workflowStatusRepository
.
saveWorkflowStatus
(
workflowstatus
);
Assert
.
assertNotNull
(
status
);
Assert
.
assertEquals
(
status
.
getWorkflowId
(),
workflowstatus
.
getWorkflowId
());
Assert
.
assertEquals
(
status
.
getAirflowRunId
(),
workflowstatus
.
getAirflowRunId
());
}
@Test
public
void
saveWorkflowStatus_return_exising_status_from_collection
()
throws
CosmosClientException
{
WorkflowStatus
workflowstatus
=
WorkflowStatus
.
builder
()
.
workflowId
(
TEST_WORKFLOW_ID
)
.
airflowRunId
(
TEST_AIRFLOW_RUN_ID
)
.
workflowStatusType
(
WorkflowStatusType
.
SUBMITTED
)
.
build
();
doThrow
(
NotFoundException
.
class
)
.
when
(
cosmosItem
)
.
read
(
any
());
WorkflowStatus
status
=
workflowStatusRepository
.
saveWorkflowStatus
(
workflowstatus
);
Assert
.
assertNotNull
(
status
);
Assert
.
assertEquals
(
status
.
getWorkflowId
(),
workflowstatus
.
getWorkflowId
());
Assert
.
assertEquals
(
status
.
getAirflowRunId
(),
workflowstatus
.
getAirflowRunId
());
}
@Test
public
void
updateWorkflowStatus
()
throws
IOException
{
doReturn
(
createWorkflowStatusDocWithStatusSubmitted
())
.
when
(
cosmosItemProperties
)
.
getObject
(
any
());
WorkflowStatus
workflowStatus
=
workflowStatusRepository
.
updateWorkflowStatus
(
TEST_WORKFLOW_ID
,
WorkflowStatusType
.
FINISHED
);
Assert
.
assertNotNull
(
workflowStatus
);
Assert
.
assertEquals
(
workflowStatus
.
getWorkflowId
(),
TEST_WORKFLOW_ID
);
Assert
.
assertEquals
(
workflowStatus
.
getAirflowRunId
(),
TEST_AIRFLOW_RUN_ID
);
Assert
.
assertNotEquals
(
workflowStatus
.
getWorkflowStatusType
(),
createWorkflowStatusDocWithStatusSubmitted
().
getWorkflowStatusType
());
}
@Test
(
expected
=
WorkflowNotFoundException
.
class
)
public
void
updateWorkflowStatus_Throw_WorkflowID_NotFound
()
throws
CosmosClientException
{
doThrow
(
NotFoundException
.
class
)
.
when
(
cosmosItem
)
.
read
(
any
());
workflowStatusRepository
.
updateWorkflowStatus
(
TEST_WORKFLOW_ID
,
WorkflowStatusType
.
FINISHED
);
}
private
WorkflowStatusDoc
createWorkflowStatusDocWithStatusFinished
()
{
WorkflowStatusDoc
workflowStatusDoc
=
new
WorkflowStatusDoc
();
workflowStatusDoc
.
setAirflowRunId
(
TEST_AIRFLOW_RUN_ID
);
workflowStatusDoc
.
setId
(
"TestID"
);
workflowStatusDoc
.
setWorkflowId
(
TEST_WORKFLOW_ID
);
workflowStatusDoc
.
setWorkflowStatusType
(
WorkflowStatusType
.
FINISHED
);
return
workflowStatusDoc
;
}
private
WorkflowStatusDoc
createWorkflowStatusDocWithStatusSubmitted
()
{
WorkflowStatusDoc
workflowStatusDoc
=
new
WorkflowStatusDoc
();
workflowStatusDoc
.
setAirflowRunId
(
TEST_AIRFLOW_RUN_ID
);
workflowStatusDoc
.
setId
(
"TestID"
);
workflowStatusDoc
.
setWorkflowId
(
TEST_WORKFLOW_ID
);
workflowStatusDoc
.
setWorkflowStatusType
(
WorkflowStatusType
.
SUBMITTED
);
return
workflowStatusDoc
;
}
}
provider/workflow-azure/src/test/java/org/opengroup/osdu/workflow/provider/azure/service/AuthenticationServiceImplTest.java
0 → 100644
View file @
018d5fc8
package
org.opengroup.osdu.workflow.provider.azure.service
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
org.opengroup.osdu.core.common.exception.UnauthorizedException
;
import
org.opengroup.osdu.workflow.provider.azure.WorkflowApplication
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
static
org
.
mockito
.
Mockito
.
doThrow
;
@RunWith
(
MockitoJUnitRunner
.
class
)
@SpringBootTest
(
classes
=
{
WorkflowApplication
.
class
})
public
class
AuthenticationServiceImplTest
{
private
static
final
String
AUTHORIZATION_TOKEN
=
"authToken"
;
private
static
final
String
PARTITION
=
"partition"
;
@Mock
private
AuthenticationServiceImpl
authenticationService
;
@Test
public
void
shouldCheckAuthentication
()
{
authenticationService
.
checkAuthentication
(
AUTHORIZATION_TOKEN
,
PARTITION
);
}
@Test
(
expected
=
UnauthorizedException
.
class
)
public
void
should_throw_unauthorized_exception_when_token_isNull
()
{
doThrow
(
UnauthorizedException
.
class
).
when
(
authenticationService
).
checkAuthentication
(
null
,
PARTITION
);
authenticationService
.
checkAuthentication
(
null
,
PARTITION
);
}
@Test
(
expected
=
UnauthorizedException
.
class
)
public
void
should_throw_unauthorized_exception_when_partition_isNull
()
{
doThrow
(
UnauthorizedException
.
class
).
when
(
authenticationService
).
checkAuthentication
(
AUTHORIZATION_TOKEN
,
null
);
authenticationService
.
checkAuthentication
(
AUTHORIZATION_TOKEN
,
null
);
}
@Test
(
expected
=
UnauthorizedException
.
class
)
public
void
shouldThrowWhenNothingIsSpecified
()
{
doThrow
(
UnauthorizedException
.
class
).
when
(
authenticationService
).
checkAuthentication
(
null
,
null
);
authenticationService
.
checkAuthentication
(
null
,
null
);
}
}
provider/workflow-azure/src/test/java/org/opengroup/osdu/workflow/provider/azure/service/SubmitIngestServiceImplTest.java
0 → 100644
View file @
018d5fc8
package
org.opengroup.osdu.workflow.provider.azure.service
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mockito
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
java.util.HashMap
;
@RunWith
(
MockitoJUnitRunner
.
Silent
.
class
)
public
class
SubmitIngestServiceImplTest
{
HashMap
<
String
,
Object
>
data
=
new
HashMap
<>();
public
void
init
()
{
data
.
put
(
"run_id"
,
"testworkflowId"
);
data
.
put
(
"conf"
,
"test"
);
}
@Test
public
void
submitIngestTestWithSuccess
()
{
SubmitIngestServiceImpl
submitIngestService
=
Mockito
.
mock
(
SubmitIngestServiceImpl
.
class
);
Mockito
.
when
(
submitIngestService
.
submitIngest
(
"test"
,
data
)).
thenReturn
(
Boolean
.
TRUE
);
}
@Test
public
void
submitIngestTestWithFailure
()
{
SubmitIngestServiceImpl
submitIngestService
=
Mockito
.
mock
(
SubmitIngestServiceImpl
.
class
);
Mockito
.
when
(
submitIngestService
.
submitIngest
(
"test"
,
data
)).
thenReturn
(
Boolean
.
FALSE
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment