Java 类org.jooq.tools.jdbc.MockDataProvider 实例源码

项目:droptools    文件:JooqHealthCheckTest.java   
@Test
public void isUnhealthyIfTransactionFails() throws Exception {
    MockDataProvider mockDataProvider = new MockDataProvider() {
        @Override
        public MockResult[] execute(MockExecuteContext ctx) throws SQLException {
            throw new SQLException("BOOM");
        }
    };

    try {
        runHealthCheck(mockDataProvider);
        assert_().fail();
    } catch (DataAccessException e) {
        assertThat(e.getMessage()).contains(validationQuery);
        assertThat(e.getMessage()).contains("BOOM");
    }
}
项目:droptools    文件:JooqHealthCheckTest.java   
private HealthCheck.Result runHealthCheck(MockDataProvider provider) throws Exception {
    MockConnection mockConnection = new MockConnection(provider) {
        @Override
        public Savepoint setSavepoint() throws SQLException {
            return new Savepoint() {
                @Override
                public int getSavepointId() throws SQLException {
                    return 0;
                }

                @Override
                public String getSavepointName() throws SQLException {
                    return "savepoint";
                }
            };
        }
    };

    Configuration configuration = new DefaultConfiguration().set(mockConnection);
    configuration.settings().setExecuteLogging(false);
    JooqHealthCheck healthCheck = new JooqHealthCheck(configuration, validationQuery);

    return healthCheck.check();
}
项目:club-tracker    文件:ListenerBrokerTest.java   
@Test
public void findListener() {
    PersonManager personManager = new PersonManager();
    Person person = personManager.createPerson();
    ClubManager clubManager = new ClubManager();
    Club club = clubManager.createClub(null, Programs.AWANA.get());

    MockDataProvider provider = selectOne((s) -> {
        s.assertUUID(person.getId(), LISTENER.ID);
    }, LISTENER, r -> {
        r.setId(person.getId().getBytes());
        r.setClubId(club.getId().getBytes());
    });

    Listener listener = setup(provider).find(person.getId(), personManager, clubManager).get();
    assertListener(person, listener);
}
项目:club-tracker    文件:ListenerBrokerTest.java   
@Test
public void findClubListeners() {
    PersonManager personManager = new PersonManager();
    Person person1 = personManager.createPerson();
    Person person2 = personManager.createPerson();
    ClubManager clubManager = new ClubManager();
    Club club = clubManager.createClub(null, Programs.AWANA.get());

    MockDataProvider provider = select((s) -> {
        s.assertUUID(club.getId(), LISTENER.CLUB_ID);
    }, (create) -> {
        Result<ListenerRecord> result = create.newResult(LISTENER);
        addClubListenerRecord(person1, club, create, result);
        addClubListenerRecord(person2, club, create, result);
        return result;
    });

    Set<Listener> listeners = setup(provider).find(club, personManager);
    Iterator<Listener> iterator = listeners.iterator();
    assertListener(person1, iterator.next());
    assertListener(person2, iterator.next());
    assertFalse(iterator.hasNext());
}
项目:club-tracker    文件:LeaderBrokerTest.java   
@Test
public void findLeader() {
    PersonManager personManager = new PersonManager();
    Person person = personManager.createPerson();
    ClubManager clubManager = new ClubManager();
    Club club = clubManager.createClub(null, Programs.AWANA.get());

    MockDataProvider provider = selectOne((s) -> {
        s.assertUUID(person.getId(), LEADER.ID);
    }, LEADER, r -> {
        r.setId(person.getId().getBytes());
        r.setClubId(club.getId().getBytes());
        r.setRole(ClubLeader.LeadershipRole.DIRECTOR.name());
    });

    ClubLeader clubLeader = setup(provider).find(person.getId(), personManager, clubManager).get();
    assertEquals(clubLeader, person.asClubLeader().get());
    assertEquals(person.getId(), clubLeader.getId());
    assertEquals(ClubLeader.LeadershipRole.DIRECTOR, clubLeader.getLeadershipRole());
}
项目:club-tracker    文件:ClubBrokerTest.java   
@Test
public void findClub() {
    String clubId = UUID.randomUUID().toString();
    ClubManager manager = new ClubManager();
    Club parent = manager.createClub(null, Programs.AWANA.get());
    String parentClubId = parent.getId();
    Curriculum curriculum = Programs.find("TnT").get();
    String curriculumId = curriculum.getId();

    MockDataProvider provider = selectOne((s) -> {
        s.assertUUID(clubId, CLUB.ID);
    }, CLUB, (r)-> {
        r.setId(clubId.getBytes());
        r.setParentClubId(parentClubId.getBytes());
        r.setCurriculum(curriculumId);
    });

    Club club = setup(provider).find(clubId, manager).get();
    assertEquals(clubId, club.getId());
    assertEquals(parent, club.getParentGroup().get());
    assertEquals(curriculum, club.getCurriculum());
}
项目:club-tracker    文件:BrokerTestUtil.java   
static Connector mockConnector(MockDataProvider provider) {
    // Put your provider into a MockConnection and use that connection
    // in your application. In this case, with a jOOQ DSLContext:
    Connection connection = new MockConnection(provider);

    return new Connector() {

        @Override
        public Connection connect() throws SQLException {
            return connection;
        }

        @Override
        public SQLDialect getDialect() {
            return SQLDialect.HSQLDB;
        }

        @Override
        public Settings getSettings() {
            return new Settings();
        }
    };
}
项目:club-tracker    文件:UserBrokerTest.java   
private User assertFindUser(Integer auth) {
    PersonManager manager = new PersonManager();
    String providerId = "Someone";
    String uniqueID = UUID.randomUUID().toString();
    String id = manager.createPerson().getId();

    MockDataProvider provider = selectOne((s) -> {
        s.assertFieldEquals(providerId, LOGIN.PROVIDER_ID);
        s.assertFieldEquals(uniqueID, LOGIN.UNIQUE_ID);
    }, LOGIN, (r)-> {
        r.setId(id.getBytes());
        r.setAuth(auth);
    });

    User user = setup(provider).find(providerId, uniqueID, manager).get();
    assertEquals(id, user.getId());
    assertEquals(providerId, user.getLoginInformation().getProviderID());
    assertEquals(uniqueID, user.getLoginInformation().getUniqueID());
    return user;
}
项目:club-tracker    文件:AddressBrokerTest.java   
@Test
public void findAddress() {
    String id = UUID.randomUUID().toString();
    MockDataProvider provider = selectOne((s) -> {
        s.assertUUID(id, ADDRESS.ID);
    }, ADDRESS, (r) -> {
        r.setId(id.getBytes());
        r.setLine1("Line 1");
        r.setLine2("Line 2");
        r.setCity("A City");
        r.setPostalCode("12345");
        r.setTerritory("NE");
        r.setCountry("US");
    });

    Address address = setup(provider).find(id).get();
    assertEquals(id, address.getId());
    assertEquals("Line 1", address.getLine1());
    assertEquals("Line 2", address.getLine2());
    assertEquals("A City", address.getCity());
    assertEquals("12345", address.getPostalCode());
    assertEquals("US", address.getCountry().getValue());
}
项目:club-tracker    文件:CeremonyBrokerTest.java   
@Test
public void findCeremony() {
    String ceremonyId = UUID.randomUUID().toString();
    LocalDate now = LocalDate.now();

    MockDataProvider provider = selectOne((s) -> s.assertUUID(ceremonyId, CEREMONY.ID), CEREMONY, (r) -> {
        r.setId(ceremonyId.getBytes());
        r.setName("Foobar");
        r.setPresentationDate(UtilityMethods.toSqlDate(now));
    });
    Optional<Ceremony> ceremony = setup(provider).find(ceremonyId);

    assertTrue(ceremony.isPresent());
    assertEquals("Foobar", ceremony.get().getName());
    assertEquals(ceremonyId, ceremony.get().getId());
    assertEquals(now, ceremony.get().presentationDate());
}
项目:club-tracker    文件:ClubberBrokerTest.java   
@Test
public void findClubber() {
    PersonManager personManager = new PersonManager();
    Person person = personManager.createPerson();
    String familyId = UUID.randomUUID().toString();
    ClubManager clubManager = new ClubManager();
    Club club = clubManager.createClub(null, Programs.AWANA.get());

    MockDataProvider provider = selectOne((s) -> {
        s.assertUUID(person.getId(), CLUBBER.ID);
    }, CLUBBER, (r)-> {
        r.setId(person.getId().getBytes());
        r.setFamilyId(familyId.getBytes());
        r.setClubId(club.getId().getBytes());
        r.setAgeGroup(AgeGroup.DefaultAgeGroup.THIRD_GRADE.name());
    });

    Clubber clubber = setup(provider, personManager, clubManager).find(person.getId()).get();
    assertEquals(person.getId(), clubber.getId());
    assertEquals(AgeGroup.DefaultAgeGroup.THIRD_GRADE, person.asClubber().get().getCurrentAgeGroup());
    assertEquals(familyId, person.getFamily().get().getId());
}
项目:club-tracker    文件:ClubberBrokerTest.java   
@Test
public void findClubberNoFamily() {
    PersonManager personManager = new PersonManager();
    Person person = personManager.createPerson();
    ClubManager clubManager = new ClubManager();
    Club club = clubManager.createClub(null, Programs.AWANA.get());

    MockDataProvider provider = selectOne((s) -> {
        s.assertUUID(person.getId(), CLUBBER.ID);
    }, CLUBBER, (r)-> {
        r.setId(person.getId().getBytes());
        r.setFamilyId(null);
        r.setClubId(club.getId().getBytes());
        r.setAgeGroup(AgeGroup.DefaultAgeGroup.THIRD_GRADE.name());
    });

    Clubber clubber = setup(provider, personManager, clubManager).find(person.getId()).get();
    assertEquals(person.getId(), clubber.getId());
    assertEquals(AgeGroup.DefaultAgeGroup.THIRD_GRADE, person.asClubber().get().getCurrentAgeGroup());

    assertFalse(clubber.getFamily().isPresent());
}
项目:club-tracker    文件:ClubberBrokerTest.java   
@Test
public void findClubberNoClub() {
    PersonManager personManager = new PersonManager();
    Person person = personManager.createPerson();
    ClubManager clubManager = new ClubManager();

    MockDataProvider provider = selectOne((s) -> {
        s.assertUUID(person.getId(), CLUBBER.ID);
    }, CLUBBER, (r)-> {
        r.setId(person.getId().getBytes());
        r.setFamilyId(null);
        r.setClubId(null);
        r.setAgeGroup(AgeGroup.DefaultAgeGroup.THIRD_GRADE.name());
    });

    Clubber clubber = setup(provider, personManager, clubManager).find(person.getId()).get();
    assertEquals(person.getId(), clubber.getId());

    assertFalse(clubber.getClub().isPresent());
}
项目:club-tracker    文件:ParentBrokerTest.java   
@Test
public void testFindsFamilyIdById() {
    String id = UUID.randomUUID().toString();
    String familyId = UUID.randomUUID().toString();


    MockDataProvider provider = selectOne(
            (s) -> s.assertUUID(id, PARENT.ID),
            PARENT,
            record->{
                record.setId(id.getBytes());
                record.setFamilyId(familyId.getBytes());
            });

    String result = setup(provider).findFamily(id).get();

    assertEquals(familyId, result);
}
项目:droptools    文件:JooqHealthCheckTest.java   
@Test
public void isHealthyIfNoExceptionIsThrown() throws Exception {
    MockDataProvider mockDataProvider = new MockDataProvider() {
        @Override
        public MockResult[] execute(MockExecuteContext ctx) throws SQLException {
            return new MockResult[0];
        }
    };

    HealthCheck.Result result = runHealthCheck(mockDataProvider);
    assertThat(result.isHealthy()).named("is healthy").isTrue();
}
项目:club-tracker    文件:ListenerBrokerTest.java   
public void testUpdatesNothing() throws Exception {
    final Listener listener = newListener();

    MockDataProvider provider = new MockDataProviderBuilder()
            .updateCount(0)
            .build();

    setup(provider).persist(listener);
}
项目:club-tracker    文件:ListenerBrokerTest.java   
@Test
public void testPersistsCorrectValues() throws Exception {
    final Listener listener = newListener();

    MockDataProvider provider = mergeProvider(assertUUID(listener));

    setup(provider).persist(listener);
}
项目:club-tracker    文件:ListenerBrokerTest.java   
@Test
public void findNoListener() {
    PersonManager personManager = new PersonManager();
    Person person = personManager.createPerson();
    ClubManager clubManager = new ClubManager();

    MockDataProvider provider = select((s) -> {
        s.assertUUID(person.getId(), LISTENER.ID);
    }, (create) -> create.newResult(LISTENER));

    assertFalse(setup(provider).find(person.getId(), personManager, clubManager).isPresent());

    assertFalse(person.asClubLeader().isPresent());
}
项目:club-tracker    文件:LeaderBrokerTest.java   
@Test(expected = DataAccessException.class)
public void testUpdatesNothing() throws Exception {
    final ClubLeader leader = newLeader();

    MockDataProvider provider = new MockDataProviderBuilder()
            .updateCount(0)
            .build();

    setup(provider).persist(leader);
}
项目:club-tracker    文件:LeaderBrokerTest.java   
@Test
public void testPersistsCorrectValues() throws Exception {
    final ClubLeader leader = newLeader();

    MockDataProvider provider = mergeProvider(assertUUID(leader), assertFields(leader));

    setup(provider).persist(leader);
}
项目:club-tracker    文件:LeaderBrokerTest.java   
@Test
public void findNoLeader() {
    PersonManager personManager = new PersonManager();
    Person person = personManager.createPerson();
    ClubManager clubManager = new ClubManager();

    MockDataProvider provider = select((s) -> {
        s.assertUUID(person.getId(), LEADER.ID);
    }, (create)->create.newResult(LEADER));

    assertFalse(setup(provider).find(person.getId(), personManager, clubManager).isPresent());

    assertFalse(person.asClubLeader().isPresent());
}
项目:club-tracker    文件:ClubBrokerTest.java   
@Test
public void testPersist() {
    final MockClub club = newClub();

    MockDataProvider provider = mergeProvider(assertUUID(club), assertFields(club));

    setup(provider).persist(club);
}
项目:club-tracker    文件:ClubBrokerTest.java   
@Test
public void testPersistProgramAsClub() {
    final Program program = newClub().getProgram();

    MockDataProvider provider = mergeProvider(assertUUID(program), assertFields(program));

    setup(provider).persist(program);
}
项目:club-tracker    文件:ClubBrokerTest.java   
@Test(expected = DataAccessException.class)
public void testUpdatesNothing() throws Exception {
    final MockClub club = newClub();

    MockDataProvider provider = new MockDataProviderBuilder()
            .updateCount(0)
            .build();

    setup(provider).persist(club);
}
项目:club-tracker    文件:ClubBrokerTest.java   
@Test
public void findNoClub() {
    String clubId = UUID.randomUUID().toString();
    ClubManager manager = new ClubManager();

    MockDataProvider provider = select((s) -> {
        s.assertUUID(clubId, CLUB.ID);
    }, (r) -> r.newResult(CLUB));

    assertFalse(setup(provider).find(clubId, manager).isPresent());
}
项目:club-tracker    文件:FamilyBrokerTest.java   
@Test(expected = DataAccessException.class)
public void testUpdatesNothing() throws Exception {
    final Family family = newFamily();

    MockDataProvider provider = new MockDataProviderBuilder()
            .updateCount(0)
            .build();

    setup(provider).persist(family);
}
项目:club-tracker    文件:ProviderBrokerTest.java   
@Test(expected = DataAccessException.class)
public void testUpdatesNothing() throws Exception {
    final Provider authProvider = newProvider();

    MockDataProvider provider = new MockDataProviderBuilder()
            .updateCount(0)
            .build();

    setup(provider).persist(authProvider);
}
项目:club-tracker    文件:ProviderBrokerTest.java   
@Test
public void testPersistsCorrectValues() throws Exception {
    final Provider authProvider = newProvider();

    MockDataProvider provider = mergeProvider(assertKey(authProvider), assertFields(authProvider));

    setup(provider).persist(authProvider);
}
项目:club-tracker    文件:ProviderBrokerTest.java   
@Test
public void findNoProviders() {
    MockDataProvider provider = select((s) -> {
        // TODO: find a way to assert empty where clause
    }, (r) -> r.newResult(PROVIDER));

    assertTrue(setup(provider).find().isEmpty());
}
项目:club-tracker    文件:ProviderBrokerTest.java   
@Test
public void findAllProviders() {
    List<ProviderRecord> allRecords = Arrays.asList(new ProviderRecord(
            "providerId",
            "site",
            "name",
            "image",
            "clientKey",
            "secret"
    ));

    MockDataProvider provider = select((s) -> {
        // TODO: find a way to assert empty where clause
    }, (r) -> {
        Result<ProviderRecord> result = r.newResult(PROVIDER);
        result.addAll(allRecords);
        return result;
    });

    List<Provider> providers = setup(provider).find();

    assertEquals(1, providers.size());

    int i=0;
    for(Provider p: providers) {
        ProviderRecord record = allRecords.get(i++);
        assertEquals(record.getClientKey(), p.getClientKey());
        assertEquals(record.getImage(), p.getImage());
        assertEquals(record.getName(), p.getName());
        assertEquals(record.getProviderId(), p.getId());
        assertEquals(record.getSite(), p.getSite());
        assertEquals(record.getSecret(), p.getSecret());
    }
}
项目:club-tracker    文件:BrokerTestUtil.java   
static MockDataProvider mergeProvider(Consumer<StatementVerifier> idFn, Consumer<StatementVerifier> fieldsFn) {
    return new MockDataProviderBuilder()
                .updateCount(1)
                .statement(StatementType.MERGE, idFn)
                .statement(StatementType.UPDATE, fieldsFn)
                .statement(StatementType.INSERT, (s) -> {
                    idFn.accept(s);
                    fieldsFn.accept(s);
                })
                .build();
}
项目:club-tracker    文件:BrokerTestUtil.java   
static MockDataProvider mergeProvider(Consumer<StatementVerifier> idFn) {
    return new MockDataProviderBuilder()
            .updateCount(1)
            .statement(StatementType.MERGE, idFn)
            .statement(StatementType.INSERT, idFn)
            .build();
}
项目:club-tracker    文件:BrokerTestUtil.java   
static <R extends UpdatableRecord<R>> MockDataProvider selectOne(
        Consumer<StatementVerifier> assertWhereFn,
        Table<R> table,
        Consumer<R> fn)
{
    return select(assertWhereFn, (create) -> {
        Result<R> result = create.newResult(table);
        R record = create.newRecord(table);
        result.add(record);
        fn.accept(record);
        return result;
    });
}
项目:club-tracker    文件:UserBrokerTest.java   
@Test
public void testPersistMerges() throws Exception {
    final User person = newUser();

    MockDataProvider provider = mergeProvider(assertUUID(person), assertNullFields());

    setup(provider).persist(person.getLoginInformation());
}
项目:club-tracker    文件:UserBrokerTest.java   
@Test(expected = DataAccessException.class)
public void testUpdatesNothing() throws Exception {
    final User person = newUser();

    MockDataProvider provider = new MockDataProviderBuilder()
            .updateCount(0)
            .build();

    setup(provider).persist(person.getLoginInformation());
}
项目:club-tracker    文件:UserBrokerTest.java   
@Test
public void testPersistsCorrectValues() throws Exception {
    final User person = newUser();
    person.resetAuth();

    MockDataProvider provider = mergeProvider(assertUUID(person), assertFields(person));

    setup(provider).persist(person.getLoginInformation());
}
项目:club-tracker    文件:OrganizationBrokerTest.java   
@Test
public void testPersistProgramAsOrganization() {
    final Program program = newProgram();

    MockDataProvider provider = mergeProvider(assertUUID(program), assertFields(program));

    setup(provider).persist(program);
}
项目:club-tracker    文件:OrganizationBrokerTest.java   
@Test
public void testPersistEmptyProgram() {
    final Program program = new ProgramAdapter(null, null, (String)null) {
        String id = UUID.randomUUID().toString();

        @Override
        public String getId() {
            return id;
        }
    };

    MockDataProvider provider = mergeProvider(assertUUID(program), assertNullFields(program));

    setup(provider).persist(program);
}
项目:club-tracker    文件:OrganizationBrokerTest.java   
@Test(expected = DataAccessException.class)
public void testUpdatesNothing() throws Exception {
    final Program club = newProgram();

    MockDataProvider provider = new MockDataProviderBuilder()
            .updateCount(0)
            .build();

    setup(provider).persist(club);
}