Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CICS Cancel #2514

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ cics_build: BUILD ATTACH (ATTACHID cics_name | PROCESS cics_name | RESOURCE cics
RECFM cics_data_value | cics_handle_response)+;

/** CANCEL (both of them) */
cics_cancel: CANCEL (ACTIVITY cics_data_value | ACQACTIVITY | ACQPROCESS | cics_cancel_reqid | cics_handle_response)*;
cics_cancel_reqid: REQID cics_name (SYSID cics_data_area |
TRANSID cics_name | cics_handle_response)*;
cics_cancel: CANCEL (cics_cancel_bts | cics_cancel_reqid);
cics_cancel_bts: (ACTIVITY cics_data_value | ACQACTIVITY | ACQPROCESS) cics_handle_response?;
cics_cancel_reqid: REQID cics_name (SYSID cics_data_area | TRANSID cics_name | cics_handle_response)*;

/** CHANGE PHRASE / PASSWORD / TASK */
cics_change: CHANGE (cics_change_phrase | cics_change_password);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2024 Broadcom.
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
*
*/

package org.eclipse.lsp.cobol.implicitDialects.cics.utility;

import org.antlr.v4.runtime.ParserRuleContext;
import org.eclipse.lsp.cobol.common.dialects.DialectProcessingContext;
import org.eclipse.lsp.cobol.common.error.ErrorSeverity;
import org.eclipse.lsp.cobol.common.error.SyntaxError;

import static org.eclipse.lsp.cobol.implicitDialects.cics.CICSParser.RULE_cics_cancel;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

/** Checks CICS Cancel rules for required and invalid options */
public class CICSCancelOptionsCheckUtility extends CICSOptionsCheckBaseUtility {

public static final int RULE_INDEX = RULE_cics_cancel;

private static final Map<String, ErrorSeverity> DUPLICATE_CHECK_OPTIONS =
new HashMap<String, ErrorSeverity>() {
{
put("CANCEL", ErrorSeverity.ERROR);
put("ACTIVITY", ErrorSeverity.ERROR);
put("ACQACTIVITY", ErrorSeverity.ERROR);
put("ACQPROCESS", ErrorSeverity.ERROR);
put("REQID", ErrorSeverity.ERROR);
put("SYSID", ErrorSeverity.ERROR);
put("TRANSID", ErrorSeverity.ERROR);
}
};

public CICSCancelOptionsCheckUtility(DialectProcessingContext context, List<SyntaxError> errors) {
super(context, errors, DUPLICATE_CHECK_OPTIONS);
}

/**
* Entrypoint to check CICS Cancel rule options
*
* @param ctx ParserRuleContext subclass containing options
* @param <E> A subclass of ParserRuleContext
*/
public <E extends ParserRuleContext> void checkOptions(E ctx) {
checkDuplicates(ctx);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public CICSOptionsCheckUtility(DialectProcessingContext context, List<SyntaxErro
CICSIssueOptionsCheckUtility.RULE_INDEX, new CICSIssueOptionsCheckUtility(context, errors));
optionsMap.put(
CICSWaitOptionsCheckUtility.RULE_INDEX, new CICSWaitOptionsCheckUtility(context, errors));
optionsMap.put(
CICSCancelOptionsCheckUtility.RULE_INDEX, new CICSCancelOptionsCheckUtility(context, errors));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
* Copyright (c) 2024 Broadcom.
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
*
*/
package org.eclipse.lsp.cobol.usecases;

import com.google.common.collect.ImmutableMap;
import org.eclipse.lsp.cobol.common.error.ErrorSource;
import org.eclipse.lsp.cobol.usecases.common.CICSTestUtils;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.eclipse.lsp4j.Range;
import org.junit.jupiter.api.Test;

import java.util.Map;

/**
* Test CICS Cancel commands. Documentation link: <a
* href="https://www.ibm.com/docs/en/cics-ts/6.x?topic=summary-cancel">CANCEL Command</a>
* <a https://www.ibm.com/docs/en/cics-ts/6.x?topic=summary-cancel-bts">CANCEL(BTS) Command</a>
* <p>This class tests all variations of the CANCEL command found in the link above.
*/
public class TestCICSCancel {

private static final String CANCEL_ACTIVITY_VALID =
"CANCEL ACTIVITY({$varOne})";

private static final String CANCEL_ACQACTIVITY_VALID =
"CANCEL ACQACTIVITY";

private static final String CANCEL_ACQPROCESS_VALID =
"CANCEL ACQPROCESS";
private static final String CANCEL_REQID_VALID =
"CANCEL REQID({$varFour})";
private static final String CANCEL_REQID_SYSID_VALID =
"CANCEL REQID({$varFour}) SYSID({$varFour})";
private static final String CANCEL_REQID_SYSID_TRANSID_VALID =
"CANCEL REQID({$varFour}) SYSID({$varFour}) TRANSID({$varFour})";
private static final String CANCEL_REQID_TRANSID_SYSID_VALID =
"CANCEL REQID({$varFour}) TRANSID({$varFour}) SYSID({$varFour}) ";

private static final String CANCEL_REQID_ACTIVITY_INVALID =
"CANCEL REQID({$varFour}) {ACTIVITY | error} ";

private static final String CANCEL_SYSID_INVALID =
"CANCEL {SYSID | errorSysid} ";
private static final String CANCEL_TRANSID_INVALID =
"CANCEL {TRANSID | errorTransid} ";
private static final String CANCEL_ACQACTIVITY_ACQPROCESS_INVALID =
"CANCEL ACQACTIVITY {ACQPROCESS | errorAcqactivityAcqProcess} ";

private static final String CANCEL_ACTIVITY_ACQPROCESS_INVALID =
"CANCEL ACTIVITY({$varOne}) {ACQPROCESS | errorActivityAcqProcess} ";
@Test
void testCancelActivityValid() {

CICSTestUtils.noErrorTest(CANCEL_ACTIVITY_VALID);
}

@Test
void testCancelAcqactivityValid() {
CICSTestUtils.noErrorTest(CANCEL_ACQACTIVITY_VALID);
}
@Test
void testCancelAcqprocessValid() {
CICSTestUtils.noErrorTest(CANCEL_ACQPROCESS_VALID);
}
@Test
void testCancelReqidValid() {
CICSTestUtils.noErrorTest(CANCEL_REQID_VALID); }
@Test
void testCancelReqidSysidValid() {
CICSTestUtils.noErrorTest(CANCEL_REQID_SYSID_VALID);
}
@Test
void testCancelReqidSysidTransidValid() {
CICSTestUtils.noErrorTest(CANCEL_REQID_SYSID_TRANSID_VALID);
}
@Test
void testCancelReqidTransidSysidValid() {
CICSTestUtils.noErrorTest(CANCEL_REQID_TRANSID_SYSID_VALID);
}

@Test
void testCancelReqidActivityInvalid() {
Map<String, Diagnostic> expectedDiagnostics =
ImmutableMap.of(
"error",
new Diagnostic(
new Range(),
"Extraneous input ACTIVITY",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText()));
CICSTestUtils.errorTest(CANCEL_REQID_ACTIVITY_INVALID, expectedDiagnostics);
}
@Test
void testCancelSysidInvalid() {
Map<String, Diagnostic> expectedDiagnostics =
ImmutableMap.of(
"errorSysid",
new Diagnostic(
new Range(),
"Syntax error on 'SYSID'",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText()));
CICSTestUtils.errorTest(CANCEL_SYSID_INVALID, expectedDiagnostics);
}
@Test
void testCancelTransidInvalid() {
Map<String, Diagnostic> expectedDiagnostics =
ImmutableMap.of(
"errorTransid",
new Diagnostic(
new Range(),
"Syntax error on 'TRANSID'",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText()));
CICSTestUtils.errorTest(CANCEL_TRANSID_INVALID, expectedDiagnostics);
}
@Test
void testCancelAcqactivityAcqprocess() {
Map<String, Diagnostic> expectedDiagnostics =
ImmutableMap.of(
"errorAcqactivityAcqProcess",
new Diagnostic(
new Range(),
"Extraneous input ACQPROCESS",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText()));
CICSTestUtils.errorTest(CANCEL_ACQACTIVITY_ACQPROCESS_INVALID, expectedDiagnostics);
}
@Test
void testCancelActivityAcqprocess() {
Map<String, Diagnostic> expectedDiagnostics =
ImmutableMap.of(
"errorActivityAcqProcess",
new Diagnostic(
new Range(),
"Extraneous input ACQPROCESS",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText()));
CICSTestUtils.errorTest(CANCEL_ACTIVITY_ACQPROCESS_INVALID, expectedDiagnostics);
}
}
Loading