/**
   * This method is used to get a details difference of two resource while considering the media
   * type.
   *
   * @param resourcePathOne resource path one
   * @param resourcePathTwo resource path two
   * @param mediaType media type
   * @return Comparison object which includes the difference parameters.
   * @throws ComparisonException
   * @throws WSDLException
   * @throws RegistryException
   * @throws UnsupportedEncodingException
   */
  public Comparison getArtifactDetailDiff(
      String resourcePathOne, String resourcePathTwo, String mediaType)
      throws ComparisonException, WSDLException, RegistryException, UnsupportedEncodingException {

    String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    Registry registry =
        RegistryCoreServiceComponent.getRegistryService().getRegistry(username, tenantId);
    Resource resourceOne = registry.get(resourcePathOne);
    Resource resourceTwo = registry.get(resourcePathTwo);

    switch (mediaType) {
      case ComparatorConstants.WSDL_MEDIA_TYPE:
        return getWSDLComparison(resourceOne, resourceTwo);
      default:
        return null;
    }
  }
  /**
   * This method is used to get the text difference of two strings.
   *
   * @param resourcePathOne resource path one.
   * @param resourcePathTwo resource path two.
   * @return Comparison object which includes the difference parameters.
   * @throws ComparisonException
   * @throws WSDLException
   * @throws RegistryException
   * @throws UnsupportedEncodingException
   */
  public Comparison getArtifactTextDiff(String resourcePathOne, String resourcePathTwo)
      throws ComparisonException, WSDLException, RegistryException, UnsupportedEncodingException {

    String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    Registry registry =
        RegistryCoreServiceComponent.getRegistryService().getRegistry(username, tenantId);
    Resource resourceOne = registry.get(resourcePathOne);
    Resource resourceTwo = registry.get(resourcePathTwo);

    DiffGeneratorFactory factory = new TextDiffGeneratorFactory();
    DiffGenerator flow = factory.getDiffGenerator();

    String resourceOneText = new String((byte[]) resourceOne.getContent(), "UTF-8");
    String resourceTwoText = new String((byte[]) resourceTwo.getContent(), "UTF-8");

    String resourceOneFormattedText = prettyFormatText(resourceOneText, resourceOne.getMediaType());
    String resourceTwoFormattedText = prettyFormatText(resourceTwoText, resourceTwo.getMediaType());
    return flow.compare(
        resourceOneFormattedText,
        resourceTwoFormattedText,
        ComparatorConstants.TEXT_PLAIN_MEDIA_TYPE);
  }
示例#3
0
  public void setUp() throws RegistryException {
    if (System.getProperty("carbon.home") == null) {
      File file = new File("src/test/resources/carbon-home");
      if (file.exists()) {
        System.setProperty("carbon.home", file.getAbsolutePath());
      }
    }

    // The line below is responsible for initializing the cache.
    CarbonContext.getCurrentContext();

    String carbonHome = System.getProperty("carbon.home");
    System.out.println("carbon home " + carbonHome);
    String carbonXMLPath =
        carbonHome
            + File.separator
            + "repository"
            + File.separator
            + "conf"
            + File.separator
            + "carbon.xml";
    RegistryConfiguration regConfig = new RegistryConfiguration(carbonXMLPath);
    RegistryCoreServiceComponent.setRegistryConfig(regConfig);

    RealmService realmService = new InMemoryRealmService();
    InputStream is;

    try {
      is = this.getClass().getClassLoader().getResourceAsStream("registry.xml");
    } catch (Exception e) {
      is = null;
    }
    ctx = RegistryContext.getBaseInstance(is, realmService);
    // RegistryConfigurationProcessor.populateRegistryConfig(is, ctx);
    ctx.setSetup(true);
    ctx.selectDBConfig("h2-db");
  }