1 package liquibase.servicelocator;
2
3 import java.io.File;
4 import java.lang.reflect.Modifier;
5 import java.net.MalformedURLException;
6 import java.net.URL;
7
8 import liquibase.database.Database;
9 import liquibase.parser.ChangeLogParser;
10 import liquibase.resource.ClassLoaderResourceAccessor;
11 import liquibase.resource.CompositeResourceAccessor;
12 import liquibase.test.TestContext;
13 import org.junit.After;
14 import static org.junit.Assert.*;
15 import org.junit.Before;
16 import org.junit.Test;
17
18 public class ServiceLocatorTest {
19 private ServiceLocator serviceLocator;
20
21 @Before
22 public void setup() throws Exception{
23 CompositeResourceAccessor resourceAccessor = new CompositeResourceAccessor(new ClassLoaderResourceAccessor(), TestContext.getInstance().getTestResourceAccessor());
24
25 serviceLocator = ServiceLocator.getInstance();
26 serviceLocator.setResourceAccessor(resourceAccessor);
27 }
28
29 @After
30 public void teardown() {
31 ServiceLocator.reset();
32 }
33
34 @Test
35 public void reset() {
36 ServiceLocator instance1 = ServiceLocator.getInstance();
37 ServiceLocator.reset();
38 assertFalse(instance1 == ServiceLocator.getInstance());
39 }
40
41
42 @Test
43 public void getClasses() throws Exception {
44 Class[] classes = serviceLocator.findClasses(ChangeLogParser.class);
45 assertTrue(classes.length > 0);
46 }
47
48 @Test
49 public void findClass() throws Exception {
50 Class[] classes = serviceLocator.findClasses(Database.class);
51 for (Class clazz : classes) {
52 assertFalse(clazz.getName()+" is abstract", Modifier.isAbstract(clazz.getModifiers()));
53 assertFalse(clazz.getName()+" is an interface", Modifier.isInterface(clazz.getModifiers()));
54 assertNotNull(clazz.getConstructors());
55 }
56 assertTrue(classes.length > 0);
57 }
58
59
60
61
62
63
64
65
66
67
68
69
70 }