Search in sources :

Example 11 with ViewNotificationContainer

use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer in project binnavi by google.

the class PostgreSQLViewNotificationParserTest method testViewInform4.

@Test
public void testViewInform4() throws CouldntLoadDataException {
    final ViewNotificationContainer container = new ViewNotificationContainer(view.getConfiguration().getId(), Optional.fromNullable(view), Optional.<Integer>absent(), Optional.<INaviModule>absent(), Optional.<INaviProject>absent(), "DELETE");
    final PostgreSQLViewNotificationParser parser = new PostgreSQLViewNotificationParser();
    parser.inform(Lists.<ViewNotificationContainer>newArrayList(container), provider);
}
Also used : PostgreSQLViewNotificationParser(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.parsers.PostgreSQLViewNotificationParser) ViewNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer) Test(org.junit.Test)

Example 12 with ViewNotificationContainer

use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer in project binnavi by google.

the class PostgreSQLViewNotificationParserTest method testViewInform3.

@Test
public void testViewInform3() throws CouldntLoadDataException {
    final boolean starState2 = true;
    view.getConfiguration().setStaredInternal(starState2);
    assertEquals(starState2, view.getConfiguration().isStared());
    final ViewNotificationContainer container = new ViewNotificationContainer(view.getConfiguration().getId(), Optional.fromNullable(view), Optional.<Integer>absent(), Optional.<INaviModule>absent(), Optional.<INaviProject>absent(), "UPDATE");
    final PostgreSQLViewNotificationParser parser = new PostgreSQLViewNotificationParser();
    parser.inform(Lists.<ViewNotificationContainer>newArrayList(container), provider);
    assertEquals(false, view.getConfiguration().isStared());
}
Also used : PostgreSQLViewNotificationParser(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.parsers.PostgreSQLViewNotificationParser) ViewNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer) Test(org.junit.Test)

Example 13 with ViewNotificationContainer

use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer in project binnavi by google.

the class PostgreSQLViewNotificationParser method parseProjectViewNotification.

/**
   * Parser for the bn_project_views notification. The function uses the
   * projectViewNotificationPattern to parse the incoming {@link PGNotification} into a
   * {@link ViewNotificationContainer}
   *
   * @param notification The {@link PGNotification} to parse.
   * @param provider The {@link SQLProvider} to access the database.
   */
private ViewNotificationContainer parseProjectViewNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = projectViewNotificationPattern.matcher(notification.getParameter());
    if (!matcher.find()) {
        throw new IllegalStateException("IE02744: compiled pattern: " + projectViewNotificationPattern.toString() + " did not match notification: " + notification.getParameter());
    }
    final Integer viewId = Integer.parseInt(matcher.group(3));
    final Optional<INaviView> view = Optional.fromNullable(ViewManager.get(provider).getView(viewId));
    final Optional<Integer> projectId = Optional.fromNullable(Integer.parseInt(matcher.group(4)));
    final Optional<INaviProject> project = Optional.fromNullable(provider.findProject(projectId.get()));
    final String databaseOperation = matcher.group(2);
    return new ViewNotificationContainer(viewId, view, projectId, Optional.<INaviModule>absent(), project, databaseOperation);
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) INaviProject(com.google.security.zynamics.binnavi.disassembly.INaviProject) Matcher(java.util.regex.Matcher) ViewNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer)

Example 14 with ViewNotificationContainer

use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer in project binnavi by google.

the class PostgreSQLViewNotificationParserTest method testViewInform2.

@Test
public void testViewInform2() throws CouldntLoadDataException {
    final String name2 = "TEST NAME STATE CHANGE";
    view.getConfiguration().setNameInternal(name2);
    assertEquals(name2, view.getConfiguration().getName());
    final ViewNotificationContainer container = new ViewNotificationContainer(view.getConfiguration().getId(), Optional.fromNullable(view), Optional.<Integer>absent(), Optional.<INaviModule>absent(), Optional.<INaviProject>absent(), "UPDATE");
    final PostgreSQLViewNotificationParser parser = new PostgreSQLViewNotificationParser();
    parser.inform(Lists.<ViewNotificationContainer>newArrayList(container), provider);
    assertEquals("DB PROJECT VIEW NAME", view.getConfiguration().getName());
}
Also used : PostgreSQLViewNotificationParser(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.parsers.PostgreSQLViewNotificationParser) ViewNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer) Test(org.junit.Test)

Example 15 with ViewNotificationContainer

use of com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer in project binnavi by google.

the class PostgreSQLViewNotificationParserTest method testModuleViewInform0.

@Test
public void testModuleViewInform0() throws CouldntLoadDataException {
    final INaviModule module = new MockModule(provider);
    final int currentUserViewSize = module.getContent().getViewContainer().getUserViews().size();
    final ViewNotificationContainer container = new ViewNotificationContainer(view.getConfiguration().getId(), Optional.fromNullable(view), Optional.of(module.getConfiguration().getId()), Optional.of(module), Optional.<INaviProject>absent(), "INSERT");
    final PostgreSQLViewNotificationParser parser = new PostgreSQLViewNotificationParser();
    parser.inform(Lists.<ViewNotificationContainer>newArrayList(container), provider);
    assertEquals(currentUserViewSize + 1, module.getContent().getViewContainer().getUserViews().size());
}
Also used : PostgreSQLViewNotificationParser(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.parsers.PostgreSQLViewNotificationParser) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) ViewNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer) Test(org.junit.Test)

Aggregations

ViewNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer)19 PostgreSQLViewNotificationParser (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.parsers.PostgreSQLViewNotificationParser)14 Test (org.junit.Test)13 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)5 INaviProject (com.google.security.zynamics.binnavi.disassembly.INaviProject)5 MockProject (com.google.security.zynamics.binnavi.disassembly.MockProject)4 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)4 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)3 Matcher (java.util.regex.Matcher)3 PGNotification (org.postgresql.PGNotification)1