Search in sources :

Example 6 with Operation

use of net.morimekta.test.providence.core.calculator.Operation in project providence by morimekta.

the class ProvidenceHelperTest method testFromJsonResource_named.

@Test
public void testFromJsonResource_named() throws IOException {
    Operation op = net.morimekta.providence.util.ProvidenceHelper.fromJsonResource("/json/calculator/named.json", Operation.kDescriptor);
    Operation expected = Operation.builder().setOperator(Operator.MULTIPLY).addToOperands(Operand.builder().setOperation(Operation.builder().setOperator(Operator.ADD).addToOperands(Operand.builder().setNumber(1234).build()).addToOperands(Operand.builder().setNumber(4.321).build()).build()).build()).addToOperands(Operand.builder().setImaginary(Imaginary.builder().setV(1.7).setI(-2.0).build()).build()).build();
    assertEquals(op, expected);
}
Also used : Operation(net.morimekta.test.providence.core.calculator.Operation) Test(org.junit.Test)

Example 7 with Operation

use of net.morimekta.test.providence.core.calculator.Operation in project providence by morimekta.

the class FileMessageRWTest method testService.

@Test
public void testService() throws IOException {
    String content = "[\"calculate\",\"call\",44,{\"op\":{\"operator\":\"ADD\",\"operands\":[]}}]";
    File test = writeContentTo(content, tmp.newFile());
    PServiceCall<Operation, Operation._Field> call = null;
    try (FileMessageReader reader = new FileMessageReader(test, new JsonSerializer())) {
        call = reader.read(Calculator.kDescriptor);
    }
    File result = tmp.newFile();
    try (FileMessageWriter writer = new FileMessageWriter(result, new JsonSerializer().named())) {
        writer.write(call);
    }
    assertThat(new String(Files.readAllBytes(result.toPath()), StandardCharsets.UTF_8), is(equalTo(content)));
}
Also used : Operation(net.morimekta.test.providence.core.calculator.Operation) JsonSerializer(net.morimekta.providence.serializer.JsonSerializer) File(java.io.File) Test(org.junit.Test)

Example 8 with Operation

use of net.morimekta.test.providence.core.calculator.Operation in project providence by morimekta.

the class PrettySerializerTest method testParse.

@Test
public void testParse() throws IOException {
    PrettySerializer serializer = new PrettySerializer();
    Operation actual = serializer.deserialize(getClass().getResourceAsStream("/json/calculator/pretty.cfg"), Operation.kDescriptor);
    assertEquals(mOperation, actual);
}
Also used : Operation(net.morimekta.test.providence.core.calculator.Operation) Operand.withOperation(net.morimekta.test.providence.core.calculator.Operand.withOperation) Test(org.junit.Test)

Aggregations

Operation (net.morimekta.test.providence.core.calculator.Operation)8 Test (org.junit.Test)7 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 File (java.io.File)2 JsonSerializer (net.morimekta.providence.serializer.JsonSerializer)2 TokenizerException (net.morimekta.providence.serializer.pretty.TokenizerException)2 EqualToMessage (net.morimekta.providence.util_internal.EqualToMessage)2 ConsumeAll (net.morimekta.test.providence.core.ConsumeAll)2 Containers (net.morimekta.test.providence.core.Containers)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 PApplicationException (net.morimekta.providence.PApplicationException)1 PApplicationExceptionType (net.morimekta.providence.PApplicationExceptionType)1 PMessage (net.morimekta.providence.PMessage)1