|
| 1 | +/** |
| 2 | + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * <p>Modifications copyright (C) 2017 Uber Technologies, Inc. |
| 5 | + * |
| 6 | + * <p>Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file |
| 7 | + * except in compliance with the License. A copy of the License is located at |
| 8 | + * |
| 9 | + * <p>http://aws.amazon.com/apache2.0 |
| 10 | + * |
| 11 | + * <p>or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 13 | + * specific language governing permissions and limitations under the License. |
| 14 | + */ |
| 15 | +package com.uber.cadence.internal.common; |
| 16 | + |
| 17 | +import static junit.framework.TestCase.assertEquals; |
| 18 | +import static org.junit.Assert.*; |
| 19 | + |
| 20 | +import com.uber.cadence.WorkflowType; |
| 21 | +import org.junit.Before; |
| 22 | +import org.junit.Test; |
| 23 | + |
| 24 | +public class StartWorkflowExecutionParametersTest { |
| 25 | + |
| 26 | + private StartWorkflowExecutionParameters params1; |
| 27 | + private StartWorkflowExecutionParameters params2; |
| 28 | + private StartWorkflowExecutionParameters params3; |
| 29 | + private StartWorkflowExecutionParameters differentParams; |
| 30 | + |
| 31 | + @Before |
| 32 | + public void setUp() { |
| 33 | + params1 = new StartWorkflowExecutionParameters(); |
| 34 | + params2 = new StartWorkflowExecutionParameters(); |
| 35 | + params3 = new StartWorkflowExecutionParameters(); |
| 36 | + differentParams = new StartWorkflowExecutionParameters(); |
| 37 | + |
| 38 | + params1.setWorkflowId("workflow123"); |
| 39 | + params1.setWorkflowType(new WorkflowType().setName("sampleWorkflow")); |
| 40 | + params1.setTaskList("taskList1"); |
| 41 | + params1.setInput(new byte[] {1, 2, 3}); |
| 42 | + params1.setExecutionStartToCloseTimeoutSeconds(60); |
| 43 | + params1.setTaskStartToCloseTimeoutSeconds(30); |
| 44 | + params1.setRetryParameters(new RetryParameters()); |
| 45 | + params1.setCronSchedule("* * * * *"); |
| 46 | + |
| 47 | + params2 = params1; |
| 48 | + params3 = params1.copy(); |
| 49 | + |
| 50 | + // Set differentParams with different values to test inequality |
| 51 | + differentParams.setWorkflowId("workflow456"); |
| 52 | + differentParams.setWorkflowType(new WorkflowType().setName("sampleWorkflow2")); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void testToString() { |
| 57 | + String expectedString = |
| 58 | + "StartWorkflowExecutionParameters{workflowId='workflow123', " |
| 59 | + + "workflowType=WorkflowType(name:sampleWorkflow), taskList='taskList1', " |
| 60 | + + "input=[1, 2, 3], executionStartToCloseTimeoutSeconds=60, " |
| 61 | + + "taskStartToCloseTimeoutSeconds=30, workflowIdReusePolicy=null, " |
| 62 | + + "retryParameters=RetryParameters{initialIntervalInSeconds=0, " |
| 63 | + + "backoffCoefficient=0.0, maximumIntervalInSeconds=0, " |
| 64 | + + "maximumAttempts=0, " |
| 65 | + + "nonRetriableErrorReasons=null, expirationIntervalInSeconds=0}, " |
| 66 | + + "cronSchedule='* * * * *', " |
| 67 | + + "memo='null', searchAttributes='null, context='null, delayStart='null'}"; |
| 68 | + |
| 69 | + assertEquals(expectedString, params1.toString()); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + public void testEquals_sameValues() { |
| 74 | + assertTrue(params1.equals(params2)); |
| 75 | + assertTrue(params2.equals(params1)); |
| 76 | + } |
| 77 | + |
| 78 | + @Test |
| 79 | + public void testEquals_differentValues() { |
| 80 | + assertFalse(params1.equals(differentParams)); |
| 81 | + assertFalse(params2.equals(differentParams)); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + public void testHashCode() { |
| 86 | + assertEquals(params1.hashCode(), params2.hashCode()); |
| 87 | + assertNotEquals(params1.hashCode(), differentParams.hashCode()); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + public void testEquals_nullAndDifferentClass() { |
| 92 | + assertFalse(params1.equals(null)); |
| 93 | + assertFalse(params1.equals("Some String")); |
| 94 | + } |
| 95 | + |
| 96 | + @Test |
| 97 | + public void testCopy() { |
| 98 | + StartWorkflowExecutionParameters copy = params1.copy(); |
| 99 | + |
| 100 | + // Verify that all properties are copied correctly |
| 101 | + assertEquals(params1.getWorkflowId(), copy.getWorkflowId()); |
| 102 | + assertEquals(params1.getWorkflowType(), copy.getWorkflowType()); |
| 103 | + assertEquals(params1.getTaskList(), copy.getTaskList()); |
| 104 | + assertArrayEquals(params1.getInput(), copy.getInput()); |
| 105 | + assertEquals( |
| 106 | + params1.getExecutionStartToCloseTimeoutSeconds(), |
| 107 | + copy.getExecutionStartToCloseTimeoutSeconds()); |
| 108 | + assertEquals( |
| 109 | + params1.getTaskStartToCloseTimeoutSeconds(), copy.getTaskStartToCloseTimeoutSeconds()); |
| 110 | + assertEquals( |
| 111 | + params1.getRetryParameters().getInitialIntervalInSeconds(), |
| 112 | + copy.getRetryParameters().getInitialIntervalInSeconds()); |
| 113 | + assertEquals( |
| 114 | + params1.getRetryParameters().getBackoffCoefficient(), |
| 115 | + copy.getRetryParameters().getBackoffCoefficient(), |
| 116 | + 0.0); |
| 117 | + assertEquals( |
| 118 | + params1.getRetryParameters().getMaximumIntervalInSeconds(), |
| 119 | + copy.getRetryParameters().getMaximumIntervalInSeconds()); |
| 120 | + assertEquals( |
| 121 | + params1.getRetryParameters().getMaximumAttempts(), |
| 122 | + copy.getRetryParameters().getMaximumAttempts()); |
| 123 | + assertEquals( |
| 124 | + params1.getRetryParameters().getExpirationIntervalInSeconds(), |
| 125 | + copy.getRetryParameters().getExpirationIntervalInSeconds()); |
| 126 | + assertEquals(params1.getCronSchedule(), copy.getCronSchedule()); |
| 127 | + } |
| 128 | +} |
0 commit comments