Fix raw type warnings
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / test / java / org / opendaylight / controller / cluster / schema / provider / impl / RemoteSchemaProviderTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.cluster.schema.provider.impl;
10
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertTrue;
14
15 import akka.dispatch.ExecutionContexts;
16 import akka.dispatch.Futures;
17 import com.google.common.io.ByteSource;
18 import com.google.common.util.concurrent.CheckedFuture;
19 import com.google.common.util.concurrent.MoreExecutors;
20 import java.io.IOException;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.mockito.Mockito;
24 import org.opendaylight.controller.cluster.schema.provider.RemoteYangTextSourceProvider;
25 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
26 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
27 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
28
29 public class RemoteSchemaProviderTest {
30
31     private static final SourceIdentifier ID = new SourceIdentifier("Test", "2015-10-30");
32
33     private RemoteSchemaProvider remoteSchemaProvider;
34     private RemoteYangTextSourceProvider mockedRemoteSchemaRepository;
35
36     @Before
37     public void setUp() {
38         mockedRemoteSchemaRepository = Mockito.mock(RemoteYangTextSourceProvider.class);
39         ExecutionContexts.fromExecutorService(MoreExecutors.newDirectExecutorService());
40         remoteSchemaProvider = new RemoteSchemaProvider(mockedRemoteSchemaRepository,
41                 ExecutionContexts.fromExecutorService(MoreExecutors.newDirectExecutorService()));
42     }
43
44     @Test
45     public void getExistingYangTextSchemaSource() throws IOException, SchemaSourceException {
46         String source = "Test";
47         YangTextSchemaSource schemaSource = YangTextSchemaSource.delegateForByteSource(ID, ByteSource.wrap(source.getBytes()));
48         YangTextSchemaSourceSerializationProxy sourceProxy = new YangTextSchemaSourceSerializationProxy(schemaSource);
49         Mockito.when(mockedRemoteSchemaRepository.getYangTextSchemaSource(ID)).thenReturn(Futures.successful(sourceProxy));
50
51         YangTextSchemaSource providedSource = remoteSchemaProvider.getSource(ID).checkedGet();
52         assertEquals(providedSource.getIdentifier(), ID);
53         assertArrayEquals(providedSource.read(), schemaSource.read());
54     }
55
56     @Test(expected = SchemaSourceException.class)
57     public void getNonExistingSchemaSource() throws Exception {
58         Futures.failed(new Exception("halo"));
59
60         Mockito.when(mockedRemoteSchemaRepository.getYangTextSchemaSource(ID)).thenReturn(
61                 Futures.<YangTextSchemaSourceSerializationProxy>failed(new SchemaSourceException("Source not provided")));
62
63         CheckedFuture<?, ?> sourceFuture = remoteSchemaProvider.getSource(ID);
64         assertTrue(sourceFuture.isDone());
65         sourceFuture.checkedGet();
66     }
67 }