Skip to content

Commit

Permalink
Add actor test
Browse files Browse the repository at this point in the history
  • Loading branch information
robertcsakany committed Jan 31, 2024
1 parent b5abf74 commit 0def5a0
Show file tree
Hide file tree
Showing 3 changed files with 341 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/*
@cached
operation JSL!ActorAccessDeclaration getId(): String {
return (self.eContainer.getId() + "/" + self.name);
}

/*

@cached
operation JSL!ActorAccessDeclaration isAggregation() : Boolean {
return jslUtils.isAggregation(self);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,313 @@
package hu.blackbelt.judo.tatami.jsl.jsl2psm.actor;

/*-
* #%L
* JUDO Tatami JSL parent
* %%
* Copyright (C) 2018 - 2022 BlackBelt Technology
* %%
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License, v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is
* available at https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
* #L%
*/

import org.slf4j.Logger;
import hu.blackbelt.epsilon.runtime.execution.impl.BufferedSlf4jLogger;
import hu.blackbelt.judo.meta.jsl.runtime.JslParser;
import hu.blackbelt.judo.meta.psm.service.BoundTransferOperation;
import hu.blackbelt.judo.meta.psm.service.TransferOperation;
import hu.blackbelt.judo.meta.psm.service.TransferOperationBehaviour;
import hu.blackbelt.judo.meta.psm.service.TransferOperationBehaviourType;
import hu.blackbelt.judo.meta.psm.service.UnboundOperation;
import hu.blackbelt.judo.tatami.jsl.jsl2psm.AbstractTest;
import lombok.Builder;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsInstanceOf.instanceOf;

@Slf4j
public class JslModel2PsmActorTest extends AbstractTest {
private static final String TARGET_TEST_CLASSES = "target/test-classes/actor";

@Override
public boolean generateBehaviours() {
return true;
}

@Override
protected String getTargetTestClasses() {
return TARGET_TEST_CLASSES;
}

@Override
protected String getTest() {
return this.getClass().getSimpleName();
}

@Override
protected Logger createLog() {
return new BufferedSlf4jLogger(log);
}

@BeforeAll
static void prepareTestFolders() throws IOException {
if (!Files.exists(Paths.get(TARGET_TEST_CLASSES))) {
Files.createDirectories(Paths.get(TARGET_TEST_CLASSES));
}
}

@Test
void testActors() throws Exception {

jslModel = JslParser.getModelFromFiles(
"ActorTestModel",
List.of(new File("src/test/resources/actor/ActorTestModel.jsl"))
);

transform();

/*
assertMappedTransferObject("MappedTransfer");
assertThat(assertMappedTransferObject("MappedTransfer").getOperations().size(), equalTo(19));
assertCrudOperation(params()
.transferName("MappedTransfer")
.operationName("deleteInstance")
.behaviour(TransferOperationBehaviourType.DELETE_INSTANCE)
.isBound(true));
assertCrudOperation(params()
.transferName("MappedTransfer")
.operationName("updateInstance")
.behaviour(TransferOperationBehaviourType.UPDATE_INSTANCE)
.isBound(true)
.inputType("MappedTransfer")
.isMappedInputType(true)
.outputType("MappedTransfer")
.isMappedOutputType(true));
assertCrudOperation(params()
.transferName("MappedTransfer")
.operationName("validateUpdateInstance")
.behaviour(TransferOperationBehaviourType.VALIDATE_UPDATE)
.isBound(true)
.inputType("MappedTransfer")
.isMappedInputType(true)
.outputType("MappedTransfer")
.isMappedOutputType(true));
assertCrudOperation(params()
.transferName("MappedTransfer")
.operationName("createInstanceOfCreateEntities")
.behaviour(TransferOperationBehaviourType.CREATE_INSTANCE)
.isBound(true)
.inputType("CreateTransfer")
.isMappedInputType(true)
.outputType("CreateTransfer")
.isMappedOutputType(true));
assertCrudOperation(params()
.transferName("MappedTransfer")
.operationName("validateCreateInstanceOfCreateEntities")
.behaviour(TransferOperationBehaviourType.VALIDATE_CREATE)
.isBound(true)
.inputType("CreateTransfer")
.isMappedInputType(true)
.outputType("CreateTransfer")
.isMappedOutputType(true));
assertCrudOperation(params()
.transferName("MappedTransfer")
.operationName("default")
.behaviour(TransferOperationBehaviourType.GET_TEMPLATE)
.isBound(false)
.outputType("MappedTransfer")
.isMappedOutputType(true));
assertCrudOperation(params()
.transferName("MappedTransfer")
.operationName("getUploadTokenForBinaryMapped")
.behaviour(TransferOperationBehaviourType.GET_UPLOAD_TOKEN)
.isBound(false)
.outputType("UploadToken")
.isMappedOutputType(false));
assertCrudOperation(params()
.transferName("MappedTransfer")
.operationName("getUploadTokenForBinaryTransient")
.behaviour(TransferOperationBehaviourType.GET_UPLOAD_TOKEN)
.isBound(false)
.outputType("UploadToken")
.isMappedOutputType(false));
assertCrudOperation(params()
.transferName("MappedTransfer")
.operationName("addReferencesToCreateEntities")
.behaviour(TransferOperationBehaviourType.ADD_REFERENCE)
.isBound(true)
.inputType("CreateTransfer")
.isMappedInputType(true));
assertCrudOperation(params()
.transferName("MappedTransfer")
.operationName("setReferencesOfCreateEntities")
.behaviour(TransferOperationBehaviourType.SET_REFERENCE)
.isBound(true)
.inputType("CreateTransfer")
.isMappedInputType(true));
assertCrudOperation(params()
.transferName("MappedTransfer")
.operationName("removeReferencesFromCreateEntities")
.behaviour(TransferOperationBehaviourType.REMOVE_REFERENCE)
.isBound(true)
.inputType("CreateTransfer")
.isMappedInputType(true));
assertCrudOperation(params()
.transferName("MappedTransfer")
.operationName("unsetReferencesOfCreateEntities")
.behaviour(TransferOperationBehaviourType.UNSET_REFERENCE)
.isBound(true)
.inputType("CreateTransfer")
.isMappedInputType(true));
assertCrudOperation(params()
.transferName("MappedTransfer")
.operationName("refreshInstance")
.behaviour(TransferOperationBehaviourType.REFRESH)
.isBound(true)
.inputType("_MappedTransferQueryCustomizer")
.isMappedInputType(false)
.outputType("MappedTransfer")
.isMappedOutputType(true));
assertCrudOperation(params()
.transferName("MappedTransfer")
.operationName("listOfCreateEntities")
.behaviour(TransferOperationBehaviourType.LIST)
.isBound(true)
.inputType("_CreateTransferQueryCustomizer")
.isMappedInputType(false)
.outputType("CreateTransfer")
.isMappedOutputType(true));
assertCrudOperation(params()
.transferName("MappedTransfer")
.operationName("getRangeForCreateEntities")
.behaviour(TransferOperationBehaviourType.GET_RANGE)
.isBound(true)
.inputType("_CreateTransferQueryCustomizer")
.isMappedInputType(false)
.outputType("CreateTransfer")
.isMappedOutputType(true));
assertCrudOperation(params()
.transferName("MappedTransfer")
.operationName("getRangeForMappedChoice")
.behaviour(TransferOperationBehaviourType.GET_RANGE)
.isBound(true)
.inputType("_MappedTransferQueryCustomizer")
.isMappedInputType(false)
.outputType("MappedTransfer")
.isMappedOutputType(true));
assertCrudOperation(params()
.transferName("MappedTransfer")
.operationName("getRangeForMappedChoiceStatic")
.behaviour(TransferOperationBehaviourType.GET_RANGE)
.isBound(true)
.inputType("_MappedTransferQueryCustomizer")
.isMappedInputType(false)
.outputType("MappedTransfer")
.isMappedOutputType(true));
assertCrudOperation(params()
.transferName("UnmappedTransfer")
.operationName("getRangeForUnmappedChoiceStatic")
.behaviour(TransferOperationBehaviourType.GET_RANGE)
.isBound(false)
.inputType("_MappedTransferQueryCustomizer")
.isMappedInputType(false)
.outputType("MappedTransfer")
.isMappedOutputType(true));
*/

}


@Builder
@Getter
private static class AssertCrudOperationParameters {

String transferName;
String operationName;
TransferOperationBehaviourType behaviour;
boolean isBound;
String inputType;
boolean isMappedInputType;
String outputType;
boolean isMappedOutputType;
}

private static AssertCrudOperationParameters.AssertCrudOperationParametersBuilder params() {
return AssertCrudOperationParameters.builder();
}

private void assertCrudOperation(AssertCrudOperationParameters.AssertCrudOperationParametersBuilder p) {

TransferOperation operation = assertTransferObjectOperation(p.transferName, p.operationName);
if (p.isBound) {
assertThat(operation, instanceOf(BoundTransferOperation.class));
} else {
assertThat(operation, instanceOf(UnboundOperation.class));
}
assertThat(operation.getBehaviour().getBehaviourType(), equalTo(p.behaviour));

if (p.inputType != null) {
assertThat(operation.getInput(), is(notNullValue()));
if (p.isMappedInputType) {
assertThat(operation.getInput().getType(), equalTo(assertMappedTransferObject(p.inputType)));
} else {
assertThat(operation.getInput().getType(), equalTo(assertUnmappedTransferObject(p.inputType)));
}
// assertThat(operation.getInput().getCardinality().getLower(), equalTo(1));
} else {
assertThat(operation.getInput(), is(nullValue()));
}
if (p.outputType != null) {
assertThat(operation.getOutput(), is(notNullValue()));
if (p.isMappedOutputType) {
assertThat(operation.getOutput().getType(), equalTo(assertMappedTransferObject(p.outputType)));
} else {
assertThat(operation.getOutput().getType(), equalTo(assertUnmappedTransferObject(p.outputType)));
}

// assertThat(operation.getOutput().getCardinality().getLower(), equalTo(1));
} else {
assertThat(operation.getOutput(), is(nullValue()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
model ActorTestModel;

type binary Binary max-file-size: 1MB mime-type: ["image/*"];
type boolean Boolean;
type date Date;
type numeric Numeric scale: 0 precision: 9;
type string String min-size: 0 max-size: 255;
type time Time;
type timestamp Timestamp;


entity User {
identifier String email;
}

transfer UserTransfer maps User as u {
field String email <= u.email update: true;
}

actor Actor maps User as u
realm: "COMPANY"
claim: "email"
identity: UserTransfer::email
{
access UserTransfer[] manager <= User.all();
};

0 comments on commit 0def5a0

Please sign in to comment.