Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d9e17c5
Testing symmetry of read/write in Adapter processing
dblevins May 8, 2025
f72e2af
Adapter on Field, Getter, Setter, Config, Class and Constructor
dblevins May 8, 2025
5284dea
Make explicit Getter and Setter adapters
dblevins May 8, 2025
753da89
Adapter on Field, Getter, Config, Class and Constructor, has a Setter
dblevins May 8, 2025
b5d4340
Adapter on Field, Setter, Config, Class and Constructor, has a Getter
dblevins May 8, 2025
d2aaa7e
Adapter on Field, Config, Class and Constructor, has a Getter and Setter
dblevins May 8, 2025
6080b90
Adapter on Field, Config, Class and Constructor, has a Getter and Fin…
dblevins May 8, 2025
1b395bf
Adapter on Config, Class and Constructor, has a Getter and Final Field
dblevins May 9, 2025
908f5f4
Adapter on Config, Class and Constructor, has a Getter and Setter
dblevins May 9, 2025
f9aaa3f
Fill out scenarios
dblevins May 9, 2025
96987ee
Checkstyle
dblevins May 9, 2025
fa95080
Move to string subpackage
dblevins May 9, 2025
b8b0dc1
Initial setup for Array versions of Adapter Symmetry tests
dblevins May 9, 2025
800ba5c
Adjusted Array Adapter Symmetry tests. Some new failures.
dblevins May 9, 2025
0b37c9b
Base Map Adapter Symmetry tests
dblevins May 9, 2025
c738270
Adjusted Adapter Symmetry tests, some new failures
dblevins May 9, 2025
0cb7333
Base Serializer/Deserializer Symmetry tests
dblevins May 13, 2025
2d9f1ef
Adjusted Serializer/Deserializer Symmetry tests
dblevins May 13, 2025
1f9335d
Behavior differs from equivalent Adapter test
dblevins May 13, 2025
ab90d7b
Behavior differs from equivalent Adapter test
dblevins May 13, 2025
88c0bd1
Behavior differs from equivalent Adapter test
dblevins May 13, 2025
99f1ab9
Behavior differs from equivalent Adapter test
dblevins May 13, 2025
d8a2169
Behavior differs from equivalent Adapter test
dblevins May 13, 2025
8cd01e4
Add Scenarios, adjust comments
dblevins May 13, 2025
e91eff0
Checkstyle
dblevins May 13, 2025
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
@@ -0,0 +1,80 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.johnzon.jsonb.symmetry;

import java.util.ArrayList;
import java.util.List;

public class Calls {

private final List<String> calls = new ArrayList<>();

public String called() {
final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();

if (stackTrace.length > 2) {
final StackTraceElement caller = stackTrace[2];
final String className = caller.getClassName();
final String methodName = caller.getMethodName();

final int lastDot = className.lastIndexOf('.');
final int lastDollar = className.lastIndexOf('$');
final String simpleName;
if (lastDollar == 0 && lastDot == 0) {
simpleName = className;
} else {
final int start = Math.max(lastDollar, lastDot) + 1;
simpleName = className.substring(start);
}

final String result = simpleName + "." + methodName;
calls.add(result);
return result;
}
return null;
}

public String called(final Object instance) {
final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();

if (stackTrace.length > 2) {
final StackTraceElement caller = stackTrace[2];
final String simpleName = instance.getClass().getSimpleName();
final String methodName = caller.getMethodName();


final String result = simpleName + "." + methodName;
calls.add(result);
return result;
}
return null;
}

public List<String> list() {
return new ArrayList<>(calls);
}

public String get() {
final String result = String.join("\n", calls);
calls.clear();
return result;
}

public void reset() {
calls.clear();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.johnzon.jsonb.symmetry;

import jakarta.json.bind.Jsonb;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public abstract class SymmetryTest {

public abstract Jsonb jsonb();

public abstract void assertWrite(final Jsonb jsonb);

public abstract void assertRead(final Jsonb jsonb);

/**
* Assert a simple write operation
*/
@Test
public void write() throws Exception {
try (final Jsonb jsonb = jsonb()) {
assertWrite(jsonb);
}
}

/**
* Assert a simple read operation
*/
@Test
public void read() throws Exception {
try (final Jsonb jsonb = jsonb()) {
assertRead(jsonb);
}
}

/**
* Validate any caching done from a write operation
* leads to a consistent result on any future
* write operations
*/
@Test
public void writeAfterWrite() throws Exception {
try (final Jsonb jsonb = jsonb()) {
assertWrite(jsonb);
assertWrite(jsonb);
assertWrite(jsonb);
assertWrite(jsonb);
}
}

/**
* Validate any caching done from a read operation
* leads to a consistent result on any future
* read operations
*/
@Test
public void readAfterRead() throws Exception {
try (final Jsonb jsonb = jsonb()) {
assertRead(jsonb);
assertRead(jsonb);
assertRead(jsonb);
assertRead(jsonb);
}
}

/**
* Validate any caching done from a read operation
* does not alter the expected behavior of a write
* operation
*/
@Test
public void writeAfterRead() throws Exception {
try (final Jsonb jsonb = jsonb()) {
assertRead(jsonb);
assertWrite(jsonb);
assertRead(jsonb);
assertWrite(jsonb);
}
}

/**
* Validate any caching done from a write operation
* does not alter the expected behavior of a read
* operation
*/
@Test
public void readAfterWrite() throws Exception {
try (final Jsonb jsonb = jsonb()) {
assertWrite(jsonb);
assertRead(jsonb);
assertWrite(jsonb);
assertRead(jsonb);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.johnzon.jsonb.symmetry.adapter.array;

import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class ArrayAdapterOnClassDirectTest extends ArrayAdapterOnClassTest {

public Jsonb jsonb() {
return JsonbBuilder.create();
}

public void assertWrite(final Jsonb jsonb) {
final Email email = new Email("test", "domain.com");
final String json = jsonb.toJson(email);
assertEquals("[\"test\",\"domain.com\",\"EmailClass.adaptToJson\"]", json);
assertEquals("EmailClass.adaptToJson", calls());
}

public void assertRead(final Jsonb jsonb) {
final String json = "[\"test\",\"domain.com\"]";
final Email email = jsonb.fromJson(json, Email.class);
assertEquals("test@domain.com:EmailClass.adaptFromJson", email.toString());
assertEquals("EmailClass.adaptFromJson", calls());
}

/**
* Fails as the adapter is not found
*/
@Test
@Ignore()
@Override
public void read() throws Exception {
super.read();
}

/**
* Fails as the adapter is not found
*/
@Test
@Ignore()
@Override
public void readAfterRead() throws Exception {
super.readAfterRead();
}

/**
* Fails as the adapter is not found on the first read
*/
@Test
@Ignore()
@Override
public void writeAfterRead() throws Exception {
super.writeAfterRead();
}

@Test
@Ignore()
@Override
public void readAfterWrite() throws Exception {
super.readAfterWrite();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.johnzon.jsonb.symmetry.adapter.array;

import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;

import static org.junit.Assert.assertEquals;

public class ArrayAdapterOnClassSimpleTest extends ArrayAdapterOnClassTest {

public Jsonb jsonb() {
return JsonbBuilder.create();
}

@Override
public void assertRead(final Jsonb jsonb) {
final String json = "{\"email\":[\"test\",\"domain.com\"]}";
final ArrayAdapterPrecedenceConfigClassTest.Contact actual = jsonb.fromJson(json, ArrayAdapterPrecedenceConfigClassTest.Contact.class);
assertEquals("Contact{email=test@domain.com:EmailClass.adaptFromJson}", actual.toString());
assertEquals("Contact.<init>\n" +
"EmailClass.adaptFromJson\n" +
"Contact.setEmail", calls());
}

@Override
public void assertWrite(final Jsonb jsonb) {
final Email email = new Email("test", "domain.com");
final ArrayAdapterPrecedenceConfigClassTest.Contact contact = new ArrayAdapterPrecedenceConfigClassTest.Contact();
contact.setEmail(email);
reset();

final String json = jsonb.toJson(contact);
assertEquals("{\"email\":[\"test\",\"domain.com\",\"EmailClass.adaptToJson\"]}", json);
assertEquals("Contact.getEmail\n" +
"EmailClass.adaptToJson", calls());
}

public static class Contact {

private Email email;

public Contact() {
CALLS.called();
}

public Email getEmail() {
CALLS.called();
return email;
}

public void setEmail(final Email email) {
CALLS.called();
this.email = email;
}

@Override
public String toString() {
return String.format("Contact{email=%s}", email);
}
}

}
Loading