International-Data-Spaces-Association / Java-Representation-of-IDS-Information-Model

Apache License 2.0
2 stars 7 forks source link

Constrain equals not working #7

Closed brianjahnke closed 3 years ago

brianjahnke commented 3 years ago

Hi, the equals method for Constraints does not seem to work. I had a quick look and believe the problem lies with the RdfResource. It does not override the equals method. Here a simple setup:

package io.dataspaceconnector;

import java.io.IOException;

import de.fraunhofer.iais.eis.Constraint;
import de.fraunhofer.iais.eis.ids.jsonld.Serializer;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class TestTest {

    @Test
    public void should_be_equals() throws IOException {
        final var input = "{\n"
                          + "  \"@context\" : {\n"
                          + "    \"ids\" : \"https://w3id.org/idsa/core/\",\n"
                          + "    \"idsc\" : \"https://w3id.org/idsa/code/\"\n"
                          + "  },\n"
                          + "  \"@type\" : \"ids:Constraint\",\n"
                          + "  \"@id\" : \"https://w3id.org/idsa/autogen/constraint/4ae656d1-2a73"
                          + "-44e3-a168-b1cbe49d4622\",\n"
                          + "  \"ids:leftOperand\" : {\n"
                          + "    \"@id\" : \"https://w3id.org/idsa/code/COUNT\"\n"
                          + "  },\n"
                          + "  \"ids:rightOperand\" : {\n"
                          + "    \"@value\" : \"5\",\n"
                          + "    \"@type\" : \"http://www.w3.org/2001/XMLSchema#double\"\n"
                          + "  },\n"
                          + "  \"ids:operator\" : {\n"
                          + "    \"@id\" : \"https://w3id.org/idsa/code/LTEQ\"\n"
                          + "  }\n"
                          + "}";

        final var deserializer = new Serializer();
        final var obj1 = deserializer.deserialize(input, Constraint.class);
        final var obj2 = deserializer.deserialize(input, Constraint.class);

        assertTrue(obj1.equals(obj2));
    }
}
maboeckmann commented 3 years ago

Hi Brian, thank you for yet another great report. Your assumption was correct. I have added an override to the equals and hashCode methods for RdfResource and TypedLiteral. Now, the test is running without error. You will find the fix in the latest SNAPSHOT (4.0.11-SNAPSHOT)