--- /dev/null
+[gerrit]
+host=git.opendaylight.org
+port=29418
+project=yangtools.git
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yangtools</artifactId>
+ <version>0.1.1-SNAPSHOT</version>
+ </parent>
+
+ <!-- FIXME: remove this once parent is bumped -->
+ <version>0.6.0-SNAPSHOT</version>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>mockito-configuration</artifactId>
+ <description>Default mockito configuration</description>
+ <packaging>jar</packaging><!-- not needed in OSGi -->
+ <name>${project.artifactId}</name>
+ <prerequisites>
+ <maven>3.0.4</maven>
+ </prerequisites>
+
+ <dependencies>
+ <!-- all those dependencies will be in test scope as mockito-configuration should be referenced as test scope dependency -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+</project>
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.mockito.configuration;
+
+import org.mockito.exceptions.base.MockitoException;
+import org.mockito.internal.invocation.InvocationsFinder;
+import org.mockito.internal.verification.api.VerificationData;
+import org.mockito.invocation.Invocation;
+import org.mockito.verification.VerificationMode;
+
+import java.util.List;
+
+/**
+ * Verifier that extracts arguments from actual invocation. Useful when deeper validation of arguments is needed.
+ *
+ */
+public class ArgumentsExtractorVerifier implements VerificationMode {
+ private Object[] arguments;
+
+ @Override
+ public void verify(VerificationData data) {
+ InvocationsFinder finder = new InvocationsFinder();
+ List<Invocation> actualInvocations = finder.findInvocations(data.getAllInvocations(), data.getWanted());
+ if (actualInvocations.size() != 1) {
+ throw new MockitoException("This verifier can only be used with 1 invocation, got " + actualInvocations.size());
+ }
+ Invocation invocation = actualInvocations.get(0);
+ arguments = invocation.getArguments();
+ invocation.markVerified();
+
+ }
+ public Object[] getArguments(){
+ return arguments;
+ }
+ }
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.mockito.configuration;
+
+import org.mockito.stubbing.Answer;
+
+/**
+ * Configuration customization for Mockito. Change default answer to {@link ThrowsUnstubbedMethodException}.
+ */
+public class MockitoConfiguration extends DefaultMockitoConfiguration {
+
+ @Override
+ public Answer<Object> getDefaultAnswer() {
+ return new ThrowsUnstubbedMethodException();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.mockito.configuration;
+
+import java.io.Serializable;
+
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+/**
+ * Answer that throws {@link UnstubbedMethodException}.
+ */
+public class ThrowsUnstubbedMethodException implements Answer<Object>, Serializable {
+ private static final long serialVersionUID = 1L;
+
+ public ThrowsUnstubbedMethodException() {
+ }
+
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ Throwable t = new UnstubbedMethodException(invocation.toString() + " was not stubbed");
+ throw t;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.mockito.configuration;
+
+
+/**
+ * Exception to be thrown on unstubbed method call.
+ */
+public class UnstubbedMethodException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ public UnstubbedMethodException(String message) {
+ super(message);
+ }
+
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
+ </encoder>
+ </appender>
+
+ <root level="DEBUG">
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.mockito.configuration;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public class ArgumentsExtractorVerifierTest {
+
+ @Mock
+ List<String> mockedList;
+
+ @Test
+ public void test() {
+ MockitoAnnotations.initMocks(this);
+ doReturn(true).when(this.mockedList).add(any(String.class));
+ final String argument = "something";
+ this.mockedList.add(argument);
+ // retrieve argument
+ final ArgumentsExtractorVerifier argumentsExtractorVerifier = new ArgumentsExtractorVerifier();
+ verify(this.mockedList, argumentsExtractorVerifier).add(any(String.class));
+ assertArrayEquals(new Object[] { argument }, argumentsExtractorVerifier.getArguments());
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.mockito.configuration;
+
+import static org.junit.Assert.*;
+
+import java.io.Closeable;
+import java.io.IOException;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class DefaultAnswerTest {
+
+ @Test
+ public void testAnswering() throws IOException {
+ Closeable mock = Mockito.mock(Closeable.class);
+ try {
+ mock.close();
+ fail();
+ } catch (UnstubbedMethodException e) {
+ assertEquals("closeable.close(); was not stubbed", e.getMessage());
+ }
+ }
+
+
+
+}
<slf4j.version>1.7.2</slf4j.version>\r
<guava.version>14.0.1</guava.version>\r
<xtend.version>2.4.3</xtend.version>\r
- <groovy.version>2.1.6</groovy.version>\r
+ <groovy.version>2.1.6</groovy.version>\r
+ <mockito.version>1.9.5</mockito.version>\r
</properties>\r
\r
<scm>\r
<module>yang</module>\r
<module>code-generator</module>\r
<module>model</module>\r
- <module>restconf</module>\r
+ <module>restconf</module>\r
+ <module>mockito-configuration</module>\r
<!-- module>third-party</module -->\r
</modules>\r
\r
<dependency>\r
<groupId>org.mockito</groupId>\r
<artifactId>mockito-all</artifactId>\r
- <version>1.9.5</version>\r
+ <version>${mockito.version}</version>\r
+ <scope>test</scope>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.mockito</groupId>\r
+ <artifactId>mockito-core</artifactId>\r
+ <version>${mockito.version}</version>\r
<scope>test</scope>\r
</dependency>\r
\r
private Map<QName, List<Node<?>>> nodeMap = new HashMap<>();
- private Map<QName, String> attributes;
+ private final Map<QName, String> attributes;
*/
private ImmutableCompositeNode(QName qname, Map<QName,String> attributes,List<Node<?>> value) {
super(qname, null, ImmutableList.copyOf(value));
- attributes = ImmutableMap.copyOf(attributes);
+ if(attributes == null) {
+ this.attributes = ImmutableMap.<QName, String>of();
+ } else {
+ this.attributes = ImmutableMap.copyOf(attributes);
+ }
init();
}
*/
public ImmutableCompositeNode(QName qname, List<Node<?>> value, ModifyAction modifyAction) {
super(qname, null, value, modifyAction);
+ attributes = ImmutableMap.of();
init();
}
} else {
ret = doc.createElementNS(null, dataType.getLocalName());
}
- if (data instanceof AttributesContainer) {
+ if (data instanceof AttributesContainer && ((AttributesContainer) data).getAttributes() != null) {
for (Entry<QName, String> attribute : ((AttributesContainer) data).getAttributes().entrySet()) {
ret.setAttributeNS(attribute.getKey().getNamespace().toString(), attribute.getKey().getLocalName(),
attribute.getValue());
XmlCodecProvider codecProvider) {
TypeDefinitionAwareCodec<Object, ? extends TypeDefinition<?>> codec = codecProvider.codecFor(schema.getType());
String text = xmlElement.getTextContent();
- Object value = codec.deserialize(text);
+ Object value;
+ if (codec != null) {
+ value = codec.deserialize(text);
+
+ } else {
+ value = xmlElement.getTextContent();
+ }
return new SimpleNodeTOImpl<Object>(schema.getQName(), null, value);
}
XmlCodecProvider codecProvider) {
TypeDefinitionAwareCodec<Object, ? extends TypeDefinition<?>> codec = codecProvider.codecFor(schema.getType());
String text = xmlElement.getTextContent();
- Object value = codec.deserialize(text);
+ Object value;
+ if (codec != null) {
+ value = codec.deserialize(text);
+
+ } else {
+ value = xmlElement.getTextContent();
+ }
return new SimpleNodeTOImpl<Object>(schema.getQName(), null, value);
}
import org.opendaylight.yangtools.yang.parser.builder.api.TypeAwareBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.impl.*;
+import org.opendaylight.yangtools.yang.parser.builder.impl.ChoiceBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.impl.ChoiceCaseBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.impl.DeviationBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.impl.ExtensionBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.impl.IdentitySchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.impl.IdentityrefTypeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.impl.UnionTypeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.util.Comparators;
import org.opendaylight.yangtools.yang.parser.util.GroupingSort;
import org.opendaylight.yangtools.yang.parser.util.GroupingUtils;
import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort;
sorted = ModuleDependencySort.sortWithContext(context, all.toArray(new ModuleBuilder[all.size()]));
}
- // resolve other augments
for (ModuleBuilder mb : sorted) {
if (mb != null) {
List<AugmentationSchemaBuilder> augments = mb.getAllAugments();
checkAugmentMandatoryNodes(augments);
+ Collections.sort(augments, Comparators.AUGMENT_COMP);
for (AugmentationSchemaBuilder augment : augments) {
if (!(augment.isResolved())) {
boolean resolved = resolveAugment(augment, mb, modules, context);
if (!resolved) {
throw new YangParseException(augment.getModuleName(), augment.getLine(),
"Error in augment parsing: failed to find augment target: " + augment);
-
}
}
}
for (ModuleImport dependency : info.getDependencies()) {
LOG.debug("Source: {} Resolving dependency: {}",identifier,dependency);
ResolutionState dependencyState = resolveDependency(dependency);
- if (dependencyState == ResolutionState.MISSING_SOURCE) {
+ if (dependencyState != ResolutionState.EVERYTHING_OK) {
potentialState = ResolutionState.MISSING_DEPENDENCY;
missingDependencies.put(identifier, dependency);
}
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
public final class Comparators {
+ /**
+ * Comparator based on alphabetical order of qname's local name.
+ */
public static final QNameComparator QNAME_COMP = new QNameComparator();
+
+ /**
+ * Comparator based on alphabetical order of local name of SchemaNode's qname.
+ */
public static final SchemaNodeComparator SCHEMA_NODE_COMP = new SchemaNodeComparator();
+ /**
+ * Comparator based on augment target path length.
+ */
+ public static final AugmentComparator AUGMENT_COMP = new AugmentComparator();
+
private Comparators() {
}
}
}
+ private static final class AugmentComparator implements Comparator<AugmentationSchemaBuilder> {
+ @Override
+ public int compare(AugmentationSchemaBuilder o1, AugmentationSchemaBuilder o2) {
+ return o1.getTargetPath().getPath().size() - o2.getTargetPath().getPath().size();
+ }
+
+ }
+
}