コード例 #1
0
 @Test
 public void ensureLoadCascadesWell() {
   User u1 = getUserService().find().matching(new FindUserByLogin()).getFirst();
   assertThat(u1.about, IsNull.notNullValue());
   assertThat(u1.about, IsInstanceOf.instanceOf(Post.class));
   assertThat(((Post) u1.about).text, IsNull.notNullValue());
 }
コード例 #2
0
 @Test
 public void ensureAPostCanHaveAValueNulled() throws IOException, ClassNotFoundException {
   Post tested = new Post().withAuthor(author).withText("ensureAPostCanHaveAValueNulled");
   tested = getPostService().create(tested);
   assertThat(tested.text, IsNull.notNullValue());
   tested.text = null;
   tested = getPostService().update(tested);
   // force reload from graph
   tested = ((IdBasedService<Post>) getPostService()).findById(tested.id);
   assertThat(tested.text, IsNull.nullValue());
 }
コード例 #3
0
  @Test
  public void responseWithoutDescriptionsCanBeRoundTripped() {
    // Act:
    final ErrorResponse response =
        createRoundTrippedResponse(new ErrorResponse(new TimeInstant(54), null, 890));

    // Assert:
    Assert.assertThat(response.getTimeStamp(), IsEqual.equalTo(new TimeInstant(54)));
    Assert.assertThat(response.getError(), IsNull.nullValue());
    Assert.assertThat(response.getMessage(), IsNull.nullValue());
    Assert.assertThat(response.getStatus(), IsEqual.equalTo(890));
  }
コード例 #4
0
  @Test
  public void parseTest() {

    System.setProperty("http.proxyHost", "myproxy");
    System.setProperty("http.proxyPort", "80");
    System.setProperty("http.nonProxyHosts", "127.0.0.1|localhost|*.company.com");

    {
      final List<Proxy> proxyList =
          ProxySelector.getDefault().select(URI.create("http://localhost:8080/confluence/xmlrpc"));

      Assert.assertThat(proxyList.isEmpty(), Is.is(false));
      Assert.assertThat(proxyList.size(), Is.is(1));

      final Proxy p = proxyList.get(0);

      System.out.printf("type=[%s] address=[%s]\n", p.type(), p.address());

      Assert.assertThat(p.type(), Is.is(Type.DIRECT));
      Assert.assertThat(p.address(), IsNull.nullValue());
    }

    {
      final List<Proxy> proxyList =
          ProxySelector.getDefault()
              .select(URI.create("http://my.company.com:8033/confluence/xmlrpc"));

      Assert.assertThat(proxyList.isEmpty(), Is.is(false));
      Assert.assertThat(proxyList.size(), Is.is(1));

      final Proxy p = proxyList.get(0);

      System.out.printf("type=[%s] address=[%s]\n", p.type(), p.address());

      Assert.assertThat(p.type(), Is.is(Type.DIRECT));
      Assert.assertThat(p.address(), IsNull.nullValue());
    }

    {
      final List<Proxy> proxyList =
          ProxySelector.getDefault().select(URI.create("http://www.google.com/confluence/xmlrpc"));

      Assert.assertThat(proxyList.isEmpty(), Is.is(false));
      Assert.assertThat(proxyList.size(), Is.is(1));

      final Proxy p = proxyList.get(0);

      System.out.printf("type=[%s] address=[%s]\n", p.type(), p.address());

      Assert.assertThat(p.type(), Is.is(Type.HTTP));
      Assert.assertThat(p.address(), IsNull.notNullValue());
    }
  }
コード例 #5
0
 @Test
 public void ensureCascadedCreateWorks() throws IOException, ClassNotFoundException {
   String METHOD_NAME = "ensureCascadedCreateWorks";
   Post toCreate = new Post();
   toCreate.text = METHOD_NAME;
   User author = new User();
   author.password = METHOD_NAME;
   author.setLogin(METHOD_NAME);
   toCreate.author = author;
   getPostService().create(toCreate);
   // Find it back
   Post found = getPostService().find().matching(new FindPostByText(METHOD_NAME)).getFirst();
   assertThat(found, IsNull.notNullValue());
   assertThat(found.author, IsNull.notNullValue());
   assertThat(found.author.getLogin(), IsNull.notNullValue());
 }
コード例 #6
0
  @Test
  public void serializeAuthorAndPosts() throws IOException, ClassNotFoundException {
    User u1 = getUserService().find().matching(new FindUserByLogin()).getFirst();
    assertThat(u1, IsNull.notNullValue());
    assertThat(u1.posts.size(), IsNot.not(0));

    // Now serialize and deserialize a second version of author
    User u2 = getUserService().find().matching(new FindUserByLogin()).getFirst();

    // Serialize it
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream output = new ObjectOutputStream(bos);
    output.writeObject(u2);
    output.close();
    bos.close();
    // then deserialize
    ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
    ObjectInputStream input = new ObjectInputStream(bis);
    User u3 = (User) input.readObject();
    input.close();
    bis.close();

    assertThat(u3, Is.is(u1));
    assertThat(u3.posts.size(), Is.is(u1.posts.size()));
    assertThat(Proxy.isProxyClass(u3.posts.getClass()), Is.is(false));
  }
コード例 #7
0
  @Before
  public void loadCredentials() {
    login = System.getProperty("wordpress.login");
    assertThat(login, IsNull.notNullValue());
    password = System.getProperty("wordpress.password");
    assertThat(password, IsNull.notNullValue());
    site = System.getProperty("wordpress.address");
    assertThat(site, IsNull.notNullValue());

    configuration =
        new WordpressConfiguration(VFSHelper.getRunningDir())
            .withLogin(login)
            .withPassword(password)
            .withSite(site);

    tested = new Wordpress();
  }
コード例 #8
0
  @Test
  public void shouldParseMotechProperties() {
    MotechProperties motechProperties =
        (MotechProperties) reader.readFromFile("/motech-properties.json", MotechProperties.class);

    assertThat(motechProperties.size(), IsEqual.equalTo(14));
    assertThat(motechProperties.get("case_name"), IsEqual.equalTo("Pankaja"));
    assertThat(motechProperties.get("family_number"), IsEqual.equalTo(""));
    assertThat(motechProperties.get("external_id"), IsNull.nullValue());
  }
コード例 #9
0
  @Test
  public void ensureMapIsWellLoaded() throws IOException, ClassNotFoundException {
    Post first = getPostService().find().matching(new FindPostByNote(1)).getFirst();

    assertThat(first.id, Is.is(1L));
    assertThat(first.annotations.size(), IsNot.not(0));
    // Now serialize all to the second
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOutput = new ObjectOutputStream(outputStream);
    objectOutput.writeObject(first);
    ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    ObjectInputStream objectInput = new ObjectInputStream(inputStream);
    Post second = (Post) objectInput.readObject();
    // Now perform some verifications
    assertThat(second, IsNull.notNullValue());
    assertThat(second.id, Is.is(1L));
    assertThat(second.annotations, IsNull.notNullValue());
    assertThat(second.annotations.size(), IsNot.not(0));
  }
コード例 #10
0
 @Test
 public void ensureFindByIdWorksWell() {
   if (getPostService() instanceof IdBasedService) {
     IdBasedService idPosts = (IdBasedService) getPostService();
     Post first = (Post) idPosts.findById(ID_POST_1);
     assertThat(first, IsNull.notNullValue());
   } else {
     Assert.fail("post service is an id based service, we all know that !");
   }
 }
  @Test
  public void openWriteCanOpenFileThatExists() throws IOException {
    // Arrange:
    final TEntityFileDescriptor descriptor = this.createDescriptor(TEST_FILE);

    // Act:
    try (final OutputStream os = descriptor.openWrite()) {
      // Assert:
      Assert.assertThat(os, IsNull.notNullValue());
    }
  }
コード例 #12
0
 @Test
 public void ensureDeletCascadesWell() {
   User other = new User().withId(2).withLogin("other login").withPassword("other password");
   long id = DELETABLE_POST;
   other.about = new Post(id, "a post about another user", 2, State.PUBLIC, other);
   getUserService().create(other);
   Post about = ((IdBasedService<Post>) getPostService()).findById(id);
   assertThat(about, IsNull.notNullValue());
   getUserService().delete(other);
   try {
     if (environment.getGraph() instanceof TransactionalGraph) {
       TransactionalGraph transactionalGraph = (TransactionalGraph) environment.getGraph();
       //				transactionalGraph.startTransaction();
     }
     about = ((IdBasedService<Post>) getPostService()).findById(id);
     assertThat(about, IsNull.nullValue());
   } catch (NoReturnableVertexException e) {
     // that exception is one of possible correct behaviours
   }
 }
コード例 #13
0
 @Test
 public void testFixture_SetterInjection() {
   MyCommandHandler commandHandler = new MyCommandHandler();
   commandHandler.setRepository(fixture.getRepository());
   fixture
       .registerAnnotatedCommandHandler(commandHandler)
       .given(new MyEvent("aggregateId", 1), new MyEvent("aggregateId", 2))
       .when(new TestCommand("aggregateId"))
       .expectReturnValue(IsNull.nullValue())
       .expectEvents(new MyEvent("aggregateId", 3));
 }
コード例 #14
0
 @Test
 public void updateAboutWithAuthor() {
   author.setLogin("new login");
   // here we modify about and let author update it for us
   String aboutText = "this is now user " + author.getLogin();
   ((Post) author.about).text = aboutText;
   getUserService().update(author);
   Post about = ((IdBasedService<Post>) getPostService()).findById(ABOUT_ID);
   assertThat(about, IsNull.notNullValue());
   assertThat(about.text, Is.is(aboutText));
 }
コード例 #15
0
  @Test
  public void canBeCreatedAroundUnknownHttpStatus() {
    // Arrange:
    final ErrorResponse response =
        new ErrorResponse(new TimeInstant(18), "exception message", -123);

    // Assert:
    Assert.assertThat(response.getTimeStamp(), IsEqual.equalTo(new TimeInstant(18)));
    Assert.assertThat(response.getError(), IsNull.nullValue());
    Assert.assertThat(response.getMessage(), IsEqual.equalTo("exception message"));
    Assert.assertThat(response.getStatus(), IsEqual.equalTo(-123));
  }
  @Test
  public void openWriteCanOpenFileThatDoesNotExist() throws IOException {
    // Arrange:
    final File file = new File(TEST_FILE_DIRECTORY, "imaginary-write.bar");
    final TEntityFileDescriptor descriptor = this.createDescriptor(file);

    // Act:
    try (final OutputStream os = descriptor.openWrite()) {
      // Assert:
      Assert.assertThat(os, IsNull.notNullValue());
    }
  }
コード例 #17
0
 private static void assertJvmInfo(JsonObject jvm) {
   assertThat(jvm, IsNull.notNullValue());
   assertThat(jvm.get("vendor"), IsNull.notNullValue());
   assertThat(jvm.get("version"), IsNull.notNullValue());
   JsonArray jPackages = (JsonArray) jvm.get("platformPackages");
   for (JsonElement jPackage : jPackages) {
     String name = jPackage.getAsString();
     if ("java.lang".equals(name)) {
       return;
     }
   }
   jPackages = (JsonArray) jvm.get("vendorPackages");
   for (JsonElement jPackage : jPackages) {
     String name = jPackage.getAsString();
     System.out.println(name);
     if ("sun.misc".equals(name)) {
       return;
     }
   }
   fail("Unable to find package java.lang");
 }
コード例 #18
0
 /**
  * According to latest modifications, the both note and text will be linked to literal vertex
  * containing value "3.0". How will it work ?
  *
  * @throws IOException
  * @throws ClassNotFoundException
  */
 @Test
 public void ensurePostCanHaveTextIdenticalToNote() throws IOException, ClassNotFoundException {
   Post third = getPostService().find().matching(new FindPostByNote(3.0f)).getFirst();
   // set value
   third.text = "3.0";
   third = getPostService().update(third);
   // get modified post (notice we test here note to be equals to 3 - AS AN INTEGER - which allows
   // us to test equality between integer and float by the way)
   third = getPostService().find().matching(new FindPostByNote(3)).getFirst();
   assertThat(third, IsNull.notNullValue());
   assertThat(third.note, Is.is(3.0f));
   assertThat(third.text, Is.is("3.0"));
 }
コード例 #19
0
    @Test
    public void addressConstantIsConsistentWithNemesisBlock() {
      // Arrange:
      final Block block = this.loadNemesisBlock();
      final Address blockAddress = block.getSigner().getAddress();

      // Assert:
      Assert.assertThat(blockAddress, IsEqual.equalTo(NEMESIS_BLOCK_INFO.getAddress()));
      Assert.assertThat(
          blockAddress.getPublicKey(),
          IsEqual.equalTo(NEMESIS_BLOCK_INFO.getAddress().getPublicKey()));
      Assert.assertThat(blockAddress.getPublicKey(), IsNull.notNullValue());
    }
コード例 #20
0
  @Test
  public void test() throws Exception {
    Properties proxyProps = readProxyProperties();
    if (proxyProps != null) {
      Set<Entry<Object, Object>> entrySet = proxyProps.entrySet();
      for (Entry<Object, Object> entry : entrySet) {
        System.setProperty(entry.getKey().toString(), entry.getValue().toString());
      }
    }

    final File javaHome = new File(System.getProperty("java.home"));
    assertThat(javaHome.exists(), Is.is(true));

    final List<File> javaHomes = new ArrayList<File>();
    javaHomes.add(javaHome);

    StringWriter writer = new StringWriter();

    ExecutionEnvironmentAnalyzer jvmWriter = new ExecutionEnvironmentAnalyzer();
    jvmWriter.analyze(javaHomes, writer);

    JsonArray jvms = parse(writer.toString());
    assertThat(jvms, IsNull.notNullValue());
    assertThat(jvms.size(), Is.is(1));
    for (JsonElement jvm : jvms) {
      assertJvmInfo((JsonObject) jvm);
    }

    javaHomes.add(javaHome);
    writer = new StringWriter();
    jvmWriter.analyze(javaHomes, writer);

    jvms = parse(writer.toString());
    assertThat(jvms, IsNull.notNullValue());
    assertThat(jvms.size(), Is.is(2));
    for (JsonElement jvm : jvms) {
      assertJvmInfo((JsonObject) jvm);
    }
  }
コード例 #21
0
 @Test
 public void ensureUpdateCascadesWell() {
   User other = new User().withId(2).withLogin("other login").withPassword("other password");
   long id = DELETABLE_POST;
   String POST_TEXT = "a post about another user";
   other.about = new Post(id, POST_TEXT, 2, State.PUBLIC, other);
   getUserService().create(other);
   Post about = ((IdBasedService<Post>) getPostService()).findById(id);
   assertThat(about, IsNull.notNullValue());
   assertThat(about.text, Is.is(POST_TEXT));
   about.text += POST_TEXT;
   getUserService().update(other);
   about = ((IdBasedService<Post>) getPostService()).findById(id);
   assertThat(about, IsNull.notNullValue());
   // we didn't change author's about Post, but the one we fetched separatly
   assertThat(about.text, Is.is(POST_TEXT));
   // Now we update the GOOD about message (yeah these cascade things are a nightmare)
   ((Post) other.about).text += POST_TEXT;
   getUserService().update(other);
   about = ((IdBasedService<Post>) getPostService()).findById(id);
   assertThat(about, IsNull.notNullValue());
   assertThat(about.text, Is.is(POST_TEXT + POST_TEXT));
 }
コード例 #22
0
 /**
  * Test to show assertion using "org.junit.Assert.assertThat()" method<br>
  *
  * @see http ://junit.org/junit/javadoc/4.5/org/hamcrest/core/package-frame.html
  */
 @Test
 public void showAssertThat() {
   String localVar = null;
   // Assert True if "this.bean" object is a instance of "ProcessingBean"
   // class
   Assert.assertThat(this.bean, IsInstanceOf.instanceOf(ProcessingBean.class));
   // Assert True if at least one assert included in the "AnyOf" operator
   // is True
   Assert.assertThat(
       this.bean.getMessage(),
       AnyOf.anyOf(IsEqual.equalTo("Hello World !"), IsNot.not(IsEqual.equalTo("Hello World !"))));
   // Assert True if all assert included in the "AllOf" operator are True
   Assert.assertThat(
       this.bean.getMessage(),
       AllOf.allOf(IsEqual.equalTo("Hello World !"), Is.is("Hello World !")));
   // Assert True if "this.bean" is the same instance than
   // "this.bean.getInstance()"
   Assert.assertThat(this.bean, IsSame.sameInstance(this.bean.getInstance()));
   // Assert True if "localVar" is null
   Assert.assertThat(localVar, IsNull.nullValue());
   // Assert True if "localVar" is not null
   localVar = "value";
   Assert.assertThat(localVar, IsNull.notNullValue());
 }
コード例 #23
0
 private Properties readProxyProperties() throws IOException {
   InputStream stream =
       getClass().getClassLoader().getResourceAsStream("META-INF/proxy.properties");
   try {
     final Properties properties = new Properties();
     assertThat(stream, IsNull.notNullValue());
     properties.load(stream);
     String property = properties.getProperty("http.proxyHost", "").trim();
     if (property.length() == 0 || property.startsWith("$")) {
       return null;
     }
     return properties;
   } finally {
     IOUtils.closeQuietly(stream);
   }
 }
コード例 #24
0
  @Test
  public void cannotReturnWalletAccountInClosedWallet() {
    // Arrange:
    final WalletAccount account = new WalletAccount();
    final TestContext context = new TestContext();
    context.originalWallet.addOtherAccount(account);

    // Act:
    context.walletServices.open(context.pair);
    context.walletServices.close(context.pair.getName());
    final WalletAccount resultAccount =
        context.walletServices.tryFindOpenAccount(account.getAddress());

    // Assert:
    Assert.assertThat(resultAccount, IsNull.nullValue());
  }
コード例 #25
0
ファイル: InstallationTest.java プロジェクト: aolarte/izpack
  @Test
  @InstallFile("samples/helloAndFinish.xml")
  public void testHelloAndFinishPanels() throws Exception {
    Image image = icons.get("JFrameIcon").getImage();
    assertThat(image, IsNull.<Object>notNullValue());

    languageDialog.initLangPack();
    installerFrameFixture =
        HelperTestMethod.prepareFrameFixture(installerFrame, installerController);

    // Hello panel
    //        installerFrameFixture.requireSize(new Dimension(640, 480));
    installerFrameFixture.button(GuiId.BUTTON_NEXT.id).click();
    installerFrameFixture.requireVisible();
    // Finish panel
  }
コード例 #26
0
  @Test
  public void renamedWalletIsNotAccessibleByOldName() {
    // Arrange:
    final WalletNamePasswordPair pair2 = createPair("n2", "p");
    final WalletDescriptor descriptor2 = createDescriptor("n2");
    final TestContext context = new TestContext();
    Mockito.when(context.descriptorFactory.createNew(pair2, FILE_EXTENSION))
        .thenReturn(descriptor2);

    // Act:
    context.walletServices.open(context.pair);
    context.walletServices.move(context.pair, pair2);

    // Assert:
    Assert.assertThat(context.walletServices.get(new WalletName("n2")), IsNull.notNullValue());
    ExceptionAssert.assertThrowsNccException(
        v -> context.walletServices.get(new WalletName("n")), NccException.Code.WALLET_IS_NOT_OPEN);
  }
コード例 #27
0
    @Test
    public void nemesisTransactionSignersHavePublicKeys() {
      // Arrange:
      final Block block = this.loadNemesisBlock();

      // Act:
      final Set<Address> signerAddresses =
          block
              .getTransactions()
              .stream()
              .map(t -> t.getSigner().getAddress())
              .collect(Collectors.toSet());

      // Assert:
      for (final Address address : signerAddresses) {
        Assert.assertThat(address.getPublicKey(), IsNull.notNullValue());
      }
    }
コード例 #28
0
    @Test
    public void nemesisBlockCanBeCreated() {
      // Act:
      final Block block = this.loadNemesisBlock();

      // Assert:
      Assert.assertThat(
          block.getSigner().getAddress(), IsEqual.equalTo(NEMESIS_BLOCK_INFO.getAddress()));
      Assert.assertThat(block.getType(), IsEqual.equalTo(-1));
      Assert.assertThat(block.getVersion(), IsEqual.equalTo(EXPECTED_VERSION));
      Assert.assertThat(block.getTimeStamp(), IsEqual.equalTo(TimeInstant.ZERO));

      // 2 multisig aggregate transactions
      Assert.assertThat(
          block.getTotalFee(), IsEqual.equalTo(EXPECTED_MULTISIG_AGGREGATE_FEE.multiply(2)));
      Assert.assertThat(block.getPreviousBlockHash(), IsEqual.equalTo(Hash.ZERO));
      Assert.assertThat(block.getHeight(), IsEqual.equalTo(BlockHeight.ONE));
      Assert.assertThat(block.getTransactions().size(), IsEqual.equalTo(NUM_NEMESIS_TRANSACTIONS));

      Assert.assertThat(block.getDifficulty(), IsEqual.equalTo(BlockDifficulty.INITIAL_DIFFICULTY));
      Assert.assertThat(block.getGenerationHash(), IsNull.notNullValue());
    }
コード例 #29
0
ファイル: ObjectChecker.java プロジェクト: akune/immutables
 public void notNull() {
   verifyUsingMatcher(IsNull.notNullValue());
 }
コード例 #30
0
 @Test
 @Ignore
 public void canLoadXMLData() {
   String xml = tested.downloadXML(WebClientFactory.getWebClient(), configuration);
   assertThat(xml, IsNull.notNullValue());
 }