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

Implementation of ENDBROWSE & ENDBR statement in CICS #2496

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
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 @@ -335,10 +335,10 @@ cics_dump: DUMP (TRANSACTION | DUMPCODE cics_name | FROM cics_data_area | LENGT
TASK | STORAGE | PROGRAM | TERMINAL | TABLES | FCT | PCT | PPT | SIT | TCT | DUMPID cics_data_area | cics_handle_response)+;

/** ENDBR */
cics_endbr: ENDBR cics_file_name (REQID cics_data_value | SYSID cics_data_area | cics_handle_response)*;
cics_endbr: ENDBR (FILE cics_name | REQID cics_data_value | SYSID cics_data_area | cics_handle_response)*;

/** ENDBROWSE (all of them) */
cics_endbrowse: ENDBROWSE (ACTIVITY | CONTAINER | EVENT | PROCESS | BROWSETOKEN cics_data_value | cics_handle_response)+;
cics_endbrowse: ENDBROWSE (ACTIVITY | CONTAINER | EVENT | PROCESS | TIMER | BROWSETOKEN cics_data_value | cics_handle_response)+;

/** ENQ */
cics_enq: ENQ (RESOURCE cics_data_area | LENGTH cics_data_value | UOW | TASK | MAXLIFETIME cics_cvda | NOSUSPEND | cics_handle_response)+;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* 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 org.eclipse.lsp.cobol.implicitDialects.cics.CICSLexer;
import org.eclipse.lsp.cobol.implicitDialects.cics.CICSParser;

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

import static org.eclipse.lsp.cobol.implicitDialects.cics.CICSParser.RULE_cics_endbr;
import static org.eclipse.lsp.cobol.implicitDialects.cics.CICSParser.RULE_cics_endbrowse;

/** Checks CICS Extract rules for required and invalid options */
public class CICSEndBrowseOptionsUtility extends CICSOptionsCheckBaseUtility {

public static final int RULE_ENDBROWSE_INDEX = RULE_cics_endbrowse;
public static final int RULE_ENDBR_INDEX = RULE_cics_endbr;

private static final Map<Integer, ErrorSeverity> DUPLICATE_CHECK_OPTIONS =
new HashMap<Integer, ErrorSeverity>() {
{
put(CICSLexer.ENDBR, ErrorSeverity.ERROR);
put(CICSLexer.FILE, ErrorSeverity.ERROR);
put(CICSLexer.REQID, ErrorSeverity.ERROR);
put(CICSLexer.SYSID, ErrorSeverity.ERROR);
put(CICSLexer.ENDBROWSE, ErrorSeverity.ERROR);
put(CICSLexer.ACTIVITY, ErrorSeverity.ERROR);
put(CICSLexer.BROWSETOKEN, ErrorSeverity.ERROR);
put(CICSLexer.CONTAINER, ErrorSeverity.ERROR);
put(CICSLexer.EVENT, ErrorSeverity.ERROR);
put(CICSLexer.PROCESS, ErrorSeverity.ERROR);
put(CICSLexer.TIMER, ErrorSeverity.ERROR);
}
};

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

/**
* Entrypoint to check CICS Extract rule options
*
* @param ctx ParserRuleContext subclass containing options
* @param <E> A subclass of ParserRuleContext
*/
public <E extends ParserRuleContext> void checkOptions(E ctx) {
if (ctx.getParent().getClass() == CICSParser.Cics_endbrContext.class)
checkEndbr((CICSParser.Cics_endbrContext) ctx.getParent());
else if (ctx.getParent().getClass() == CICSParser.Cics_endbrowseContext.class)
checkEndBrowse((CICSParser.Cics_endbrowseContext) ctx.getParent());
checkDuplicates(ctx.getParent());
}

private void checkEndbr(CICSParser.Cics_endbrContext ctx) {
checkHasMandatoryOptions(ctx.FILE(), ctx, "FILE");
}

private void checkEndBrowse(CICSParser.Cics_endbrowseContext ctx) {
if (ctx.ACTIVITY().isEmpty() && ctx.PROCESS().isEmpty() && ctx.EVENT().isEmpty()
&& ctx.CONTAINER().isEmpty() && ctx.TIMER().isEmpty()) {
checkHasMandatoryOptions(ctx.ACTIVITY(), ctx, "ACTIVITY or CONTAINER or EVENT or PROCESS or TIMER");

}
checkHasMandatoryOptions(ctx.BROWSETOKEN(), ctx, "BROWSETOKEN");
if (!ctx.ACTIVITY().isEmpty()) {
checkHasIllegalOptions(ctx.CONTAINER(), "CONTAINER");
checkHasIllegalOptions(ctx.EVENT(), "EVENT");
checkHasIllegalOptions(ctx.PROCESS(), "PROCESS");
checkHasIllegalOptions(ctx.TIMER(), "TIMER");
} else if (!ctx.CONTAINER().isEmpty()) {
checkHasIllegalOptions(ctx.ACTIVITY(), "ACTIVITY");
checkHasIllegalOptions(ctx.EVENT(), "EVENT");
checkHasIllegalOptions(ctx.PROCESS(), "PROCESS");
checkHasIllegalOptions(ctx.TIMER(), "TIMER");
} else if (!ctx.EVENT().isEmpty()) {
checkHasIllegalOptions(ctx.CONTAINER(), "CONTAINER");
checkHasIllegalOptions(ctx.ACTIVITY(), "ACTIVITY");
checkHasIllegalOptions(ctx.PROCESS(), "PROCESS");
checkHasIllegalOptions(ctx.TIMER(), "TIMER");
} else if (!ctx.PROCESS().isEmpty()) {
checkHasIllegalOptions(ctx.CONTAINER(), "CONTAINER");
checkHasIllegalOptions(ctx.EVENT(), "EVENT");
checkHasIllegalOptions(ctx.ACTIVITY(), "ACTIVITY");
checkHasIllegalOptions(ctx.TIMER(), "TIMER");
} else if (!ctx.TIMER().isEmpty()) {
checkHasIllegalOptions(ctx.CONTAINER(), "CONTAINER");
checkHasIllegalOptions(ctx.EVENT(), "EVENT");
checkHasIllegalOptions(ctx.PROCESS(), "PROCESS");
checkHasIllegalOptions(ctx.ACTIVITY(), "ACTIVITY");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ public CICSOptionsCheckUtility(DialectProcessingContext context, List<SyntaxErro
new CICSWaitOptionsCheckUtility(context, errors));
optionsMap.put(
CICSCancelOptionsCheckUtility.RULE_INDEX, new CICSCancelOptionsCheckUtility(context, errors));

optionsMap.put(
CICSEndBrowseOptionsUtility.RULE_ENDBR_INDEX,
new CICSEndBrowseOptionsUtility(context, errors));
optionsMap.put(
CICSEndBrowseOptionsUtility.RULE_ENDBROWSE_INDEX,
new CICSEndBrowseOptionsUtility(context, errors));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* 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 ENDBR & ENDBROWSE commands. Documentation link: <a
* href="https://www.ibm.com/docs/en/cics-ts/6.x?topic=summary-endbrowse-activity">ENDBROWSE Command</a>
* href="https://www.ibm.com/docs/en/cics-ts/6.x?topic=summary-endbr">ENDBR Command</a>
*
* <p>This class tests all variations of the ENDBR & ENDBROWSE command found in the link above.
*/
public class TestCICSEndBrowse {
// ENDBR
private static final String ENDBR_FILE_VALID = "ENDBR FILE({$varFour})";
private static final String ENDBR_FILE_REQID_VALID = "ENDBR FILE({$varFour}) REQID({$varOne})";
private static final String ENDBR_FILE_SYSID_VALID = "ENDBR FILE({$varFour}) SYSID({$varOne})";
private static final String ENDBR_FILE_REQID_SYSID_VALID = "ENDBR FILE({$varFour}) REQID({$varOne}) SYSID({$varFive})";

// ENDBROWSE
private static final String ENDBROWSE_ACTIVITY_VALID = "ENDBROWSE ACTIVITY BROWSETOKEN({$varOne})";
private static final String ENDBROWSE_ACTIVITY_INVALID = "ENDBROWSE ACTIVITY {ACTIVITY|error1} BROWSETOKEN({$varOne})";
private static final String ENDBROWSE_CONTAINER_VALID = "ENDBROWSE CONTAINER BROWSETOKEN({$varOne})";
private static final String ENDBROWSE_EVENT_VALID = "ENDBROWSE EVENT BROWSETOKEN({$varOne})";
private static final String ENDBROWSE_EVENT_INVALID = "ENDBROWSE EVENT {TIMER|error1} BROWSETOKEN({$varOne})";
private static final String ENDBROWSE_TIMER_VALID = "ENDBROWSE TIMER BROWSETOKEN({$varOne})";
private static final String ENDBROWSE_PROCESS_VALID = "ENDBROWSE PROCESS BROWSETOKEN({$varOne})";

@Test
void testEndbrFileValid() {
CICSTestUtils.noErrorTest(ENDBR_FILE_VALID);
}

@Test
void testEndbrFileReqidValid() {
CICSTestUtils.noErrorTest(ENDBR_FILE_REQID_VALID);
}

@Test
void testEndbrFileSysidValid() {
CICSTestUtils.noErrorTest(ENDBR_FILE_SYSID_VALID);
}

@Test
void testEndbrFileReqidSysidValid() {
CICSTestUtils.noErrorTest(ENDBR_FILE_REQID_SYSID_VALID);
}


@Test
void testEndbrowseActivityValid() {
CICSTestUtils.noErrorTest(ENDBROWSE_ACTIVITY_VALID);
}

@Test
void testEndbrowseActivityInvalid() {
Map<String, Diagnostic> expectedDiagnostics =
ImmutableMap.of(
"error1",
new Diagnostic(
new Range(),
"Excessive options provided for: ACTIVITY",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText()));
CICSTestUtils.errorTest(ENDBROWSE_ACTIVITY_INVALID, expectedDiagnostics);
}

@Test
void testEndbrowseContainerValid() {
CICSTestUtils.noErrorTest(ENDBROWSE_CONTAINER_VALID);
}

@Test
void testEndbrowseEventValid() {
CICSTestUtils.noErrorTest(ENDBROWSE_EVENT_VALID);
}

@Test
void testEndbrowseEventInvalid() {
Map<String, Diagnostic> expectedDiagnostics =
ImmutableMap.of(
"error1",
new Diagnostic(
new Range(),
"Invalid option provided: TIMER",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText()));
CICSTestUtils.errorTest(ENDBROWSE_EVENT_INVALID, expectedDiagnostics);
}

@Test
void testEndbrowseProcessValid() {
CICSTestUtils.noErrorTest(ENDBROWSE_PROCESS_VALID);
}

@Test
void testEndbrowseTimerValid() {
CICSTestUtils.noErrorTest(ENDBROWSE_TIMER_VALID);
}
}
Loading