*/
package org.opendaylight.controller.config.yang.store.impl;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.anyCollectionOf;
-import static org.mockito.Mockito.*;
-
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.List;
-
+import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.opendaylight.controller.config.yang.store.api.YangStoreException;
import org.opendaylight.controller.config.yang.store.api.YangStoreSnapshot;
+import org.opendaylight.yangtools.yang.model.api.Module;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleListener;
-import com.google.common.collect.Lists;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyCollectionOf;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
public class ExtenderYangTrackerCustomizerTest {
- private ExtenderYangTrackerCustomizer tested;
+ private ExtenderYangTracker tested;
@Mock
private MbeParser parser;
@Mock
- private YangStoreSnapshot yangStoreSnapshot;
+ private YangStoreSnapshotImpl yangStoreSnapshot;
+ @Mock
+ private BundleContext bundleContext;
+
+ private Map<String, Map.Entry<Module, String>> moduleMap = Maps.newHashMap();
@Before
public void setUp() throws YangStoreException {
- MockitoAnnotations.initMocks(this);
- tested = new ExtenderYangTrackerCustomizer(parser);
+ moduleMap.put("1", new Map.Entry<Module, String>() {
+ @Override
+ public Module getKey() {
+ return mock(Module.class);
+ }
+
+ @Override
+ public String getValue() {
+ return "v";
+ }
+
+ @Override
+ public String setValue(String value) {
+ return "v";
+ }
+ });
+
+ MockitoAnnotations.initMocks(this);
+ doNothing().when(bundleContext).addBundleListener(any(BundleListener.class));
+ doReturn(new Bundle[0]).when(bundleContext).getBundles();
+ tested = new ExtenderYangTracker(parser, Optional.<Pattern>absent(), bundleContext);
doReturn(yangStoreSnapshot).when(parser).parseYangFiles(
anyCollectionOf(InputStream.class));
doReturn(22).when(yangStoreSnapshot).countModuleMXBeanEntries();
doReturn("mock yang store").when(yangStoreSnapshot).toString();
doNothing().when(yangStoreSnapshot).close();
+ doReturn(moduleMap).when(yangStoreSnapshot).getModuleMap();
+ doReturn(Collections.emptyMap()).when(yangStoreSnapshot).getModuleMXBeanEntryMap();
}
@Test
returnedStore = tested.getYangStoreSnapshot();
- assertEquals(yangStoreSnapshot, returnedStore);
+ assertEquals(yangStoreSnapshot.getModuleMap(), returnedStore.getModuleMap());
tested.removedBundle(bundle, null, null);
tested.getYangStoreSnapshot();
bundle = getMockedBundle(10, false);
tested.addingBundle(bundle, null);
- for(int i = 0; i< 10; i++){
+ for(int i = 0; i< 20; i++){
tested.getYangStoreSnapshot();
}
- verify(parser, times(5)).parseYangFiles(
- anyCollectionOf(InputStream.class));
+ verify(parser, times(5)).parseYangFiles(anyCollectionOf(InputStream.class));
returnedStore = tested.getYangStoreSnapshot();
verifyNoMoreInteractions(parser);
- assertEquals(yangStoreSnapshot, returnedStore);
}
int bundleCounter = 1;
doReturn(1L).when(mock).getBundleId();
doReturn("mockedBundle").when(mock).toString();
+ doReturn("mockedBundle").when(mock).getSymbolicName();
return mock;
}