|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Broadcom. |
| 3 | + * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. |
| 4 | + * |
| 5 | + * This program and the accompanying materials are made |
| 6 | + * available under the terms of the Eclipse Public License 2.0 |
| 7 | + * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| 8 | + * |
| 9 | + * SPDX-License-Identifier: EPL-2.0 |
| 10 | + * |
| 11 | + * Contributors: |
| 12 | + * Broadcom, Inc. - initial API and implementation |
| 13 | + * |
| 14 | + */ |
| 15 | +package org.eclipse.lsp.cobol.usecases; |
| 16 | + |
| 17 | +import com.google.common.collect.ImmutableMap; |
| 18 | +import org.eclipse.lsp.cobol.common.error.ErrorSource; |
| 19 | +import org.eclipse.lsp.cobol.usecases.common.CICSTestUtils; |
| 20 | +import org.eclipse.lsp4j.Diagnostic; |
| 21 | +import org.eclipse.lsp4j.DiagnosticSeverity; |
| 22 | +import org.eclipse.lsp4j.Range; |
| 23 | +import org.junit.jupiter.api.Test; |
| 24 | + |
| 25 | +import java.util.Map; |
| 26 | + |
| 27 | +/** |
| 28 | + * Test CICS SUSPEND command. Documentation link: <a |
| 29 | + * href="https://www.ibm.com/docs/en/cics-ts/6.x?topic=summary-suspend">SUSPEND |
| 30 | + * Command</a> |
| 31 | + * |
| 32 | + * <p>This class tests all variations of the SUSPEND command found in the link above. |
| 33 | + */ |
| 34 | +public class TestCicsSuspend { |
| 35 | + private static final String SUSPEND_BARE = "SUSPEND"; |
| 36 | + private static final String SUSPEND_ACTIVITY = "SUSPEND ACTIVITY({$varOne})"; |
| 37 | + private static final String SUSPEND_ACQACTIVITY = "SUSPEND ACQACTIVITY"; |
| 38 | + private static final String SUSPEND_ACQPROCESS = "SUSPEND ACQPROCESS"; |
| 39 | + |
| 40 | + private static final String SUSPEND_INVALID_ONE = "SUSPEND {ACQACTIVITY|error1} {ACQPROCESS|error1}"; |
| 41 | + private static final String SUSPEND_INVALID_TWO = "SUSPEND {ACTIVITY|error1}({$varOne}) {ACQPROCESS|error1}"; |
| 42 | + private static final String SUSPEND_INVALID_THREE = "SUSPEND {ACQACTIVITY|error1} {ACTIVITY|error1}({$varOne})"; |
| 43 | + |
| 44 | + @Test |
| 45 | + void testSuspend() { |
| 46 | + CICSTestUtils.noErrorTest(SUSPEND_BARE); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + void testSuspendActivity() { |
| 51 | + CICSTestUtils.noErrorTest(SUSPEND_ACTIVITY); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + void testSuspendAcqActivity() { |
| 56 | + CICSTestUtils.noErrorTest(SUSPEND_ACQACTIVITY); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + void testSuspendAcqProcess() { |
| 61 | + CICSTestUtils.noErrorTest(SUSPEND_ACQPROCESS); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + void testSuspendInvalidOne() { |
| 66 | + Map<String, Diagnostic> expectedDiagnostic = |
| 67 | + ImmutableMap.of( |
| 68 | + "error1", |
| 69 | + new Diagnostic( |
| 70 | + new Range(), |
| 71 | + "Exactly one option required, options are mutually exclusive: ACQACTIVITY or ACQPROCESS or ACTIVITY", |
| 72 | + DiagnosticSeverity.Error, |
| 73 | + ErrorSource.PARSING.getText())); |
| 74 | + CICSTestUtils.errorTest(SUSPEND_INVALID_ONE, expectedDiagnostic); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + void testSuspendInvalidTwo() { |
| 79 | + Map<String, Diagnostic> expectedDiagnostic = |
| 80 | + ImmutableMap.of( |
| 81 | + "error1", |
| 82 | + new Diagnostic( |
| 83 | + new Range(), |
| 84 | + "Exactly one option required, options are mutually exclusive: ACQACTIVITY or ACQPROCESS or ACTIVITY", |
| 85 | + DiagnosticSeverity.Error, |
| 86 | + ErrorSource.PARSING.getText())); |
| 87 | + CICSTestUtils.errorTest(SUSPEND_INVALID_TWO, expectedDiagnostic); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + void testSuspendInvalidThree() { |
| 92 | + Map<String, Diagnostic> expectedDiagnostic = |
| 93 | + ImmutableMap.of( |
| 94 | + "error1", |
| 95 | + new Diagnostic( |
| 96 | + new Range(), |
| 97 | + "Exactly one option required, options are mutually exclusive: ACQACTIVITY or ACQPROCESS or ACTIVITY", |
| 98 | + DiagnosticSeverity.Error, |
| 99 | + ErrorSource.PARSING.getText())); |
| 100 | + CICSTestUtils.errorTest(SUSPEND_INVALID_THREE, expectedDiagnostic); |
| 101 | + } |
| 102 | + |
| 103 | +} |
0 commit comments