Drop unneeded generic type specifiers
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / repo / SharedSchemaContextFactoryTest.java
1 package org.opendaylight.yangtools.yang.parser.repo;
2
3 import static org.junit.Assert.assertNotNull;
4
5 import com.google.common.collect.Lists;
6 import com.google.common.util.concurrent.CheckedFuture;
7 import com.google.common.util.concurrent.Futures;
8 import org.junit.Before;
9 import org.junit.Test;
10 import org.mockito.Mock;
11 import org.mockito.MockitoAnnotations;
12 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
13 import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
14 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
15 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
16 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
17 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
18 import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
19 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
20 import org.opendaylight.yangtools.yang.parser.util.ASTSchemaSource;
21 import org.opendaylight.yangtools.yang.parser.util.TextToASTTransformer;
22
23 public class SharedSchemaContextFactoryTest {
24
25     private final SharedSchemaRepository repository = new SharedSchemaRepository("test");
26
27     @Mock
28     private SchemaSourceFilter filter;
29     private SourceIdentifier s1;
30     private SourceIdentifier s2;
31
32     @Before
33     public void setUp() throws Exception {
34         MockitoAnnotations.initMocks(this);
35
36         final ResourceYangSource source1 = new ResourceYangSource("/ietf/ietf-inet-types@2010-09-24.yang");
37         final ResourceYangSource source2 = new ResourceYangSource("/ietf/iana-timezones@2012-07-09.yang");
38         s1 = new SourceIdentifier("ietf-inet-types", "2010-09-24");
39         s2 = new SourceIdentifier("iana-timezones", "2012-07-09");
40
41         final TextToASTTransformer transformer = TextToASTTransformer.create(repository, repository);
42         repository.registerSchemaSourceListener(transformer);
43
44         repository.registerSchemaSource(new SchemaSourceProvider<YangTextSchemaSource>() {
45             @Override
46             public CheckedFuture<YangTextSchemaSource, SchemaSourceException> getSource(final SourceIdentifier sourceIdentifier) {
47                 return Futures.immediateCheckedFuture(source1);
48             }
49         }, PotentialSchemaSource.create(s1, YangTextSchemaSource.class, 1));
50
51         repository.registerSchemaSource(new SchemaSourceProvider<YangTextSchemaSource>() {
52             @Override
53             public CheckedFuture<YangTextSchemaSource, SchemaSourceException> getSource(final SourceIdentifier sourceIdentifier) {
54                 return Futures.immediateCheckedFuture(source2);
55             }
56         }, PotentialSchemaSource.create(s2, YangTextSchemaSource.class, 1));
57     }
58
59     @Test
60     public void testCreateSchemaContextWithDuplicateRequiredSources() throws Exception {
61         final SharedSchemaContextFactory sharedSchemaContextFactory = new SharedSchemaContextFactory(repository, filter);
62         final CheckedFuture<SchemaContext, SchemaResolutionException> schemaContext = sharedSchemaContextFactory.createSchemaContext(Lists.newArrayList(s1, s1, s2));
63         assertNotNull(schemaContext.checkedGet());
64     }
65
66     @Test
67     public void testSourceRegisteredWithDifferentSI() throws Exception {
68         final ResourceYangSource source1 = new ResourceYangSource("/ietf/ietf-inet-types@2010-09-24.yang");
69         final ResourceYangSource source2 = new ResourceYangSource("/ietf/iana-timezones@2012-07-09.yang");
70         s1 = source1.getIdentifier();
71         s2 = source2.getIdentifier();
72
73         final SettableSchemaProvider<ASTSchemaSource> provider = SharedSchemaRepositoryTest.getImmediateYangSourceProviderFromResource("/no-revision/imported@2012-12-12.yang");
74         provider.setResult();
75         provider.register(repository);
76
77         // Register the same provider under source id without revision
78         final SourceIdentifier sIdWithoutRevision = new SourceIdentifier(provider.getId().getName());
79         repository.registerSchemaSource(provider, PotentialSchemaSource.create(
80                 sIdWithoutRevision, ASTSchemaSource.class, PotentialSchemaSource.Costs.IMMEDIATE.getValue()));
81
82         final SharedSchemaContextFactory sharedSchemaContextFactory = new SharedSchemaContextFactory(repository, filter);
83         final CheckedFuture<SchemaContext, SchemaResolutionException> schemaContext = sharedSchemaContextFactory.createSchemaContext(Lists.newArrayList(sIdWithoutRevision, provider.getId()));
84         assertNotNull(schemaContext.checkedGet());
85     }
86 }