Пример #1
0
  @Test
  public void testWriteSmallManifestWithOnlyStaticFiles() {

    HashSet<String> set = new HashSet<String>();
    set.add("a.stuff");
    set.add("b.stuff");

    String manifest = writer.writeManifest(set, new HashSet<String>());

    List<String> lines = Arrays.asList(manifest.split("\\r?\\n"));

    Assert.assertEquals(14, lines.size());

    Assert.assertEquals("CACHE MANIFEST", lines.get(0));
    Assert.assertTrue(lines.get(1).startsWith("# Unique id #"));

    Assert.assertTrue(lines.contains("CACHE:"));
    int indexOf2 = lines.indexOf("CACHE:");
    Assert.assertEquals("a.stuff", lines.get(indexOf2 + 2));
    Assert.assertEquals("b.stuff", lines.get(indexOf2 + 3));

    Assert.assertTrue(lines.contains("NETWORK:"));
    int indexOf = lines.indexOf("NETWORK:");
    Assert.assertEquals("*", lines.get(indexOf + 1));
  }
Пример #2
0
  @Test
  public void testWriteManifestTestException2() {
    try {
      writer.writeManifest(null, new HashSet<String>());
      Assert.fail("expected exception did not occur");
    } catch (IllegalArgumentException e) {

    }
  }
Пример #3
0
  @Test
  public void testWriteEmptyManifest() {

    String manifest = writer.writeManifest(new HashSet<String>(), new HashSet<String>());

    List<String> lines = Arrays.asList(manifest.split("\\r?\\n"));

    Assert.assertEquals(12, lines.size());

    Assert.assertEquals("CACHE MANIFEST", lines.get(0));
    Assert.assertTrue(lines.get(1).startsWith("# Unique id #"));

    Assert.assertTrue(lines.contains("CACHE:"));
    Assert.assertTrue(lines.contains("NETWORK:"));
    int indexOf = lines.indexOf("NETWORK:");
    Assert.assertEquals("*", lines.get(indexOf + 1));
  }
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    String moduleName = getModuleName(req);

    String baseUrl = getBaseUrl(req);

    Set<BindingProperty> computedBindings = calculateBindinPropertiesForClient(req);

    String strongName = getPermutationStrongName(baseUrl, moduleName, computedBindings);

    if (strongName != null) {
      String manifest =
          readManifest(
              baseUrl
                  + moduleName
                  + "/"
                  + strongName
                  + PermutationMapLinker.PERMUTATION_MANIFEST_FILE_ENDING);
      serveStringManifest(req, resp, manifest);
      return;
    }

    boolean isIPhoneWithoutCookie = isIphoneWithoutCookie(computedBindings);
    boolean isIPadWithoutCookie = isIpadWithoutCookie(computedBindings);

    if (isIPhoneWithoutCookie || isIPadWithoutCookie) {
      Set<BindingProperty> nonRetinaMatch = new HashSet<BindingProperty>();
      Set<BindingProperty> retinaMatch = new HashSet<BindingProperty>();

      if (isIPhoneWithoutCookie) {
        computedBindings.remove(MgwtOsPropertyProvider.iPhone_undefined);
        nonRetinaMatch.add(MgwtOsPropertyProvider.iPhone);
        retinaMatch.add(MgwtOsPropertyProvider.retina);
      }

      if (isIPadWithoutCookie) {
        computedBindings.remove(MgwtOsPropertyProvider.iPad_undefined);
        nonRetinaMatch.add(MgwtOsPropertyProvider.iPad);
        retinaMatch.add(MgwtOsPropertyProvider.iPad_retina);
      }

      nonRetinaMatch.addAll(computedBindings);
      retinaMatch.addAll(computedBindings);

      String moduleNameNonRetina = getPermutationStrongName(baseUrl, moduleName, nonRetinaMatch);
      String moduleNameRetina = getPermutationStrongName(baseUrl, moduleName, retinaMatch);

      if (moduleNameNonRetina != null && moduleNameRetina != null) {

        Set<String> filesForPermutation =
            getFilesForPermutation(baseUrl, moduleName, moduleNameNonRetina);
        filesForPermutation.addAll(getFilesForPermutation(baseUrl, moduleName, moduleNameRetina));

        ManifestWriter manifestWriter = new ManifestWriter();
        String writeManifest =
            manifestWriter.writeManifest(new HashSet<String>(), filesForPermutation);
        serveStringManifest(req, resp, writeManifest);
        return;
      }
    }

    Iterator<BindingProperty> temp = computedBindings.iterator();
    while (temp.hasNext()) {
      BindingProperty a = temp.next();
      String b = a.getName();
      String c = a.getValue();
      System.out.println(b + ": " + c);
    }

    throw new ServletException("unkown device");
  }