Skip to content
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 @@ -7,6 +7,7 @@
import java.util.List;
import java.util.stream.Collectors;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -40,11 +41,22 @@ public class BridiElementEndToEndTest implements BridiTestData {
@Autowired
BridiElementFactory bridiElementFactory;

@BeforeEach
void setUp() {
sumtiRepository.findAll().forEach(x -> sumtiRepository.delete(x));
bridiReferenceRepository.findAll()
.forEach(x -> bridiReferenceRepository.delete(x));
}

@Test
void test() throws IOException {
assertTrue(inez.getBridiReferenceRepository() == bridiReferenceRepository);
assertTrue(bridiElementSystemInitialization.inez == inez);
bridiElementSystemInitialization.apply();
BridiElement elementModel = bridiElementFactory.apply(ELEMENT_MODEL_ID);
assertTrue(elementModel.getChildren()
.anyMatch(x -> x.getReferences().map(y -> y.id).toList()
.contains(ElementConstants.IS_FUNCTION_FOR_ID)));
BridiElement root = bridiElementFactory.apply(ROOT_ID);
String rootXml = loadResourceAsString("root.xml");
String theXml = root.toXml();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package io.github.magwas.inez.element;

import static org.mockito.Mockito.verify;

import java.io.IOException;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;

import io.github.magwas.testing.TestBase;

public class BridiElementSystemInitializationServiceTest extends TestBase
implements ElementConstants {

@InjectMocks
public BridiElementSystemInitializationService bridiElementSystemInitialization;

@BeforeEach
public void setUp() throws Throwable {
super.setUp();
bridiElementSystemInitialization.apply();
}

@Test
@DisplayName("creates sumti IS_A")
void test() throws IOException {
verify(bridiElementSystemInitialization.inez).createSumti(IS_A_ID,
IS_A_REPR);
}

@Test
@DisplayName("creates sumti CONTAINS")
void test1() throws IOException {
verify(bridiElementSystemInitialization.inez).createSumti(CONTAINS_ID,
CONTAINS_REPR);
}

@Test
@DisplayName("creates sumti ROOT")
void test2() throws IOException {
verify(bridiElementSystemInitialization.inez).createSumti(ROOT_ID, ROOT_ID);
}

@Test
@DisplayName("creates sumti THING")
void test3() throws IOException {
verify(bridiElementSystemInitialization.inez).createSumti(THING_ID,
THING_ID);
}

@Test
@DisplayName("creates sumti CONTAINER")
void test4() throws IOException {
verify(bridiElementSystemInitialization.inez).createSumti(CONTAINER_ID,
CONTAINER_ID);
}

@Test
@DisplayName("creates sumti UNPLACED")
void test5() throws IOException {
verify(bridiElementSystemInitialization.inez).createSumti(UNPLACED_ID,
UNPLACED_ID);
}

@Test
@DisplayName("creates sumti TRUE")
void test6() throws IOException {
verify(bridiElementSystemInitialization.inez).createSumti(TRUE_ID, TRUE_ID);
}

@Test
@DisplayName("creates sumti FALSE")
void test7() throws IOException {
verify(bridiElementSystemInitialization.inez).createSumti(FALSE_ID,
FALSE_ID);
}

@Test
@DisplayName("creates sumti IS_FUNCTION_FOR")
void test8() throws IOException {
verify(bridiElementSystemInitialization.inez)
.createSumti(IS_FUNCTION_FOR_ID, IS_FUNCTION_FOR_REPR);
}

@Test
@DisplayName("creates sumti SAVE_FUNCTION_REF")
void test9() throws IOException {
verify(bridiElementSystemInitialization.inez)
.createSumti(SAVE_FUNCTION_REF_ID, SAVE_FUNCTION_REF_ID);
}

@Test
@DisplayName("creates sumti DOSAVE")
void test10() throws IOException {
verify(bridiElementSystemInitialization.inez).createSumti(DOSAVE_ID,
DOSAVE_REPR);
}

@Test
@DisplayName("creates sumti DIAGRAM")
void test11() throws IOException {
verify(bridiElementSystemInitialization.inez).createSumti(DIAGRAM_ID,
DIAGRAM_ID);
}

@Test
@DisplayName("creates sumti DIAGRAM_ELEMENT")
void test12() throws IOException {
verify(bridiElementSystemInitialization.inez)
.createSumti(DIAGRAM_ELEMENT_ID, DIAGRAM_ELEMENT_REPR);
}

@Test
@DisplayName("creates bridis from the definition file")
void test13() throws IOException {
verify(bridiElementSystemInitialization.inez)
.createFromdefinitions(ELEMENT_DEFINITIONS_RESOURCE);
}

@Test
@DisplayName("logs success")
void test14() throws IOException {
verify(bridiElementSystemInitialization.logger)
.info("BridiElement system initialized");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,26 @@
import io.github.magwas.inez.parse.IdUtil;

public interface BridiElementTestData extends BridiFieldTestData {
String DOG_ID = "id:dog";
String CONTAINS_ID = "CONTAINS";
String ROOT_ID = "ROOT";
String ELEMENT_MODEL_ID = "id:elementModel";
String CONTAINER_ID = "CONTAINER";
String CONTAINS_ELEMENT_REPR = "{my model} contains {alice}";
String CONTAINS_ELEMENT_ID = IdUtil.createID(CONTAINS_ELEMENT_REPR);
String MY_MODEL_REPR = "my model";
String MY_MODEL_ID = IdUtil.createID(MY_MODEL_REPR);
String FOLDER_ID = IdUtil.createID("folder");
String ALICE_IS_A_HUMAN_ID = "id:{alice} is a {human}";
String HUMAN_IS_A_ANIMAL_ID = "id:{human} is a {animal}";
String DOG_IS_A_ANIMAL_ID = "id:{dog} is a {animal}";
String MY_MODEL_IS_A_FOLDER_ID = "id:{my model} is a {folder}";
List<String> CONTAINS_ELEMENT_REFERENCES = List.of(CONTAINS_ID, MY_MODEL_ID,
ALICE_ID);
String HUMAN_REPR = "human";
String HUMAN_ID = IdUtil.createID(HUMAN_REPR);
Set<String> MY_FOLDER_CHILDREN = Set.of(ALICE_ID, HUMAN_ID, IS_A_ID);
Set<String> MY_FOLDER_CHILDREN = Set.of(ALICE_ID, HUMAN_ID, DOG_ID,
MY_MODEL_IS_A_FOLDER_ID, DOG_IS_A_ANIMAL_ID, HUMAN_IS_A_ANIMAL_ID,
ALICE_IS_A_HUMAN_ID);

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class CreateBridiElementServiceTest extends TestBase

@BeforeEach
@Override
public void setUp() {
public void setUp() throws Throwable {
super.setUp();
element = createBridiElement.apply(MY_MODEL_ID, HUMAN_ID, ALICE_REPR);
@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -22,7 +23,6 @@
import io.github.magwas.inez.BridiTestData;
import io.github.magwas.inez.InezImpl;
import io.github.magwas.inez.TestConfig;
import io.github.magwas.inez.element.ElementConstants;
import io.github.magwas.inez.functions.Save;
import io.github.magwas.inez.osgi.SpringBootBundleActivator;
import io.github.magwas.runtime.LogUtil;
Expand All @@ -37,7 +37,7 @@ class QueryProcessorEndToEndTest implements BridiTestData {
InezImpl inez;

@BeforeEach
void setUp() {
void setUp() throws IOException {
ServiceReference<Save> sr = mock(ServiceReference.class);
BundleContext ctx = mock(BundleContext.class);
when((ServiceReference<Save>) ctx
Expand All @@ -50,7 +50,6 @@ void setUp() {

@Test
void test1() {

inez.create(TEST_TEXT).peek(x -> LogUtil.debug("created:" + x)).toList();
assertEquals(List.of(ALICE),
inez.findAllByRepresentation(ALICE_REPR).toList());
Expand All @@ -62,8 +61,6 @@ void test1() {
"{cecile} {{$?} {banana}}");
assertQuery(Set.of(ALICE_EATS_BANANA, ALICE_EATS_CHIPS),
"{alice} {{eats} {$?}}");
inez.createSumti(ElementConstants.IS_FUNCTION_FOR,
"{0} is function for {1}");
assertQuery(Set.of("putty"), "doSave {" + "putty" + "}");
assertEquals(1, inez.findAllByRepresentation("putty").count());
List<Bridi> putty = inez.findAllByRepresentation("putty").toList();
Expand Down
3 changes: 1 addition & 2 deletions inez.model.tests/src/main/resources/mymodel.definition
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
{my model} is a {folder}
{my model} contains {alice}
{my model} contains {human}
{my model} contains {dog}
{human} is a {animal}
{alice} is a {human}
{my model} contains {[{0} is a {1}]}
{my model} contains {[{my model} contains {alice}]}
{dog} is a {animal}
30 changes: 25 additions & 5 deletions inez.model.tests/src/main/resources/mymodel.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
<element id='id:my model' type='id:folder' name='my model'>
<references>
</references>
<element id='IS_A' type='THING' name='{0} is a {1}'>
<element id='id:alice' type='id:human' name='alice'>
</element>
<element id='id:dog' type='id:animal' name='dog'>
</element>
<element id='id:human' type='id:animal' name='human'>
</element>
<element id='id:{alice} is a {human}' type='THING' name='{alice} is a {human}'>
<references>
<reference>IS_A</reference>
<reference>id:alice</reference>
<reference>id:human</reference>
</references>
</element>
<element id='id:alice' type='id:human' name='alice'>
<element id='id:{dog} is a {animal}' type='THING' name='{dog} is a {animal}'>
<references>
<reference>IS_A</reference>
<reference>id:dog</reference>
<reference>id:animal</reference>
</references>
</element>
<element id='id:human' type='id:animal' name='human'>
<element id='id:{human} is a {animal}' type='THING' name='{human} is a {animal}'>
<references>
<reference>IS_A</reference>
<reference>id:human</reference>
<reference>id:animal</reference>
</references>
</element>
<element id='id:{my model} is a {folder}' type='THING' name='{my model} is a {folder}'>
<references>
<reference>IS_A</reference>
<reference>id:my model</reference>
<reference>id:folder</reference>
</references>
</element>
</element>
Loading
Loading