Skip to content

Commit

Permalink
Merge pull request #707 from goldmansachs/xml-security
Browse files Browse the repository at this point in the history
Improve test coverage
  • Loading branch information
opatrascoiu authored Sep 9, 2024
2 parents e64addd + efb68f7 commit 47f73ef
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2016 Goldman Sachs.
*
* Licensed 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 com.gs.dmn.serialization.jackson;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.cfg.DeserializerFactoryConfig;
import com.fasterxml.jackson.databind.deser.BeanDeserializerFactory;
import com.fasterxml.jackson.databind.deser.DefaultDeserializationContext;
import com.fasterxml.jackson.databind.deser.DeserializerFactory;
import com.fasterxml.jackson.databind.node.TextNode;
import com.fasterxml.jackson.databind.node.TreeTraversingParser;
import com.gs.dmn.serialization.xstream.dom.NSElement;
import org.junit.jupiter.api.Test;

import java.io.IOException;

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

class NSElementDeserializerTest {
private final NSElementDeserializer deserializer = new NSElementDeserializer();

@Test
void testDeserialize() throws IOException {
JsonNode node = new TextNode("text");
JsonParser parser = new TreeTraversingParser(node);
parser.setCodec(new ObjectMapper());
DeserializerFactoryConfig config = new DeserializerFactoryConfig();
DeserializerFactory df = new BeanDeserializerFactory(config);
DeserializationContext context = new DefaultDeserializationContext.Impl(df);
NSElement deserialize = deserializer.deserialize(parser, context);
assertNotNull(deserialize);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2016 Goldman Sachs.
*
* Licensed 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 com.gs.dmn.serialization.jackson;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;
import com.fasterxml.jackson.databind.util.TokenBuffer;
import com.gs.dmn.serialization.xstream.dom.NSElement;
import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.assertTrue;

public class NSElementSerializerTest {
private final NSElementSerializer serializer = new NSElementSerializer();

@Test
public void testSerialize() throws IOException {
NSElement element = new NSElement(null, "prefix", "namespace");
ObjectCodec codec = new ObjectMapper();
JsonGenerator generator = new TokenBuffer(codec, false);
SerializerProvider serializers = new DefaultSerializerProvider.Impl();
serializer.serialize(element, generator, serializers);
assertTrue(true);
}
}

0 comments on commit 47f73ef

Please sign in to comment.