Skip to content

Commit

Permalink
add unit test for createDAGDescriptor method in DescriptorManage
Browse files Browse the repository at this point in the history
  • Loading branch information
zeyu10 committed Oct 25, 2024
1 parent 1ee9504 commit db25f4d
Showing 1 changed file with 79 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.weibo.rill.flow.service.converter.DAGDescriptorConverter
import com.weibo.rill.flow.olympicene.core.model.dag.DAG
import com.weibo.rill.flow.olympicene.core.model.dag.DescriptorPO
import com.weibo.rill.flow.olympicene.core.model.dag.DescriptorVO
import org.apache.commons.codec.digest.DigestUtils
import spock.lang.Specification

class DescriptorManagerTest extends Specification {
Expand Down Expand Up @@ -193,5 +194,82 @@ class DescriptorManagerTest extends Specification {
result.descriptor == descriptorContent
}


def "test createDAGDescriptor with valid input"() {
given:
def businessId = "testBusiness"
def featureName = "testFeature"
def alias = "testAlias"
def descriptorVO = new DescriptorVO()
def dag = new DAG(workspace: businessId, dagName: featureName)
def descriptorPO = new DescriptorPO("test descriptor content")
def md5 = DigestUtils.md5Hex(descriptorPO.getDescriptor())

when:
def result = descriptorManager.createDAGDescriptor(businessId, featureName, alias, descriptorVO)

then:
1 * dagDescriptorConverter.convertDescriptorVOToDAG(descriptorVO) >> dag
1 * dagDescriptorConverter.convertDAGToDescriptorPO(dag) >> descriptorPO
1 * redisClient.eval(_, businessId, _, _) >> "OK"
result == "${businessId}:${featureName}:md5_${md5}"
}

def "test createDAGDescriptor with null descriptorVO"() {
given:
def businessId = "testBusiness"
def featureName = "testFeature"
def alias = "testAlias"

when:
descriptorManager.createDAGDescriptor(businessId, featureName, alias, null)

then:
thrown(TaskException)
}

def "test createDAGDescriptor with invalid businessId"() {
given:
def businessId = "invalid business"
def featureName = "testFeature"
def alias = "testAlias"
def descriptorVO = new DescriptorVO()

when:
descriptorManager.createDAGDescriptor(businessId, featureName, alias, descriptorVO)

then:
thrown(TaskException)
}

def "test createDAGDescriptor with mismatched businessId"() {
given:
def businessId = "testBusiness"
def featureName = "testFeature"
def alias = "testAlias"
def descriptorVO = new DescriptorVO()
def dag = new DAG(workspace: "differentBusiness", dagName: featureName)

when:
descriptorManager.createDAGDescriptor(businessId, featureName, alias, descriptorVO)

then:
1 * dagDescriptorConverter.convertDescriptorVOToDAG(descriptorVO) >> dag
thrown(TaskException)
}

def "test createDAGDescriptor with mismatched featureName"() {
given:
def businessId = "testBusiness"
def featureName = "testFeature"
def alias = "testAlias"
def descriptorVO = new DescriptorVO()
def dag = new DAG(workspace: businessId, dagName: "differentFeature")

when:
descriptorManager.createDAGDescriptor(businessId, featureName, alias, descriptorVO)

then:
1 * dagDescriptorConverter.convertDescriptorVOToDAG(descriptorVO) >> dag
thrown(TaskException)
}
}

0 comments on commit db25f4d

Please sign in to comment.