@Test public void testNameGenerationWhenRegionAndWhdNameWithDelimiterExceedsMaximumLengthAndAfterReduceEndsWithDot() { String vhdName = "cb-hdp-26-1907121707-osDisk.cc5baaaa-717e-4551-b7ae-aaaa03c72a6aa.vhd"; String region = "South East Asia"; String actual = CustomVMImageNameProvider.get(region, vhdName); Assert.assertTrue(IMAGE_NAME_PATTERN.matcher(actual).matches()); Assert.assertEquals("cb-hdp-26-1907121707-osDisk.cc5baaaa-717e-4551-b7ae-aaaa03c72a6aa.-southeastasia", actual); }
public static String get(String region, String vhdName) { String name = vhdName + DELIMITER + region.toLowerCase().replaceAll("\\s", ""); if (name.length() > NAME_MAXIMUM_LENGTH) { int diff = name.length() - NAME_MAXIMUM_LENGTH; int calculatedEndIndexOfVhdName = vhdName.length() - diff; name = vhdName.substring(0, calculatedEndIndexOfVhdName) + '-' + region.toLowerCase().replaceAll("\\s", ""); } return name; }
CustomVMImageNameProvider { public static String get(String region, String vhdName) { String name = vhdName + DELIMITER + region.toLowerCase().replaceAll("\\s", ""); if (name.length() > NAME_MAXIMUM_LENGTH) { int diff = name.length() - NAME_MAXIMUM_LENGTH; int calculatedEndIndexOfVhdName = vhdName.length() - diff; name = vhdName.substring(0, calculatedEndIndexOfVhdName) + '-' + region.toLowerCase().replaceAll("\\s", ""); } return name; } }
CustomVMImageNameProvider { public static String get(String region, String vhdName) { String name = vhdName + DELIMITER + region.toLowerCase().replaceAll("\\s", ""); if (name.length() > NAME_MAXIMUM_LENGTH) { int diff = name.length() - NAME_MAXIMUM_LENGTH; int calculatedEndIndexOfVhdName = vhdName.length() - diff; name = vhdName.substring(0, calculatedEndIndexOfVhdName) + '-' + region.toLowerCase().replaceAll("\\s", ""); } return name; } private  CustomVMImageNameProvider(); }
CustomVMImageNameProvider { public static String get(String region, String vhdName) { String name = vhdName + DELIMITER + region.toLowerCase().replaceAll("\\s", ""); if (name.length() > NAME_MAXIMUM_LENGTH) { int diff = name.length() - NAME_MAXIMUM_LENGTH; int calculatedEndIndexOfVhdName = vhdName.length() - diff; name = vhdName.substring(0, calculatedEndIndexOfVhdName) + '-' + region.toLowerCase().replaceAll("\\s", ""); } return name; } private  CustomVMImageNameProvider(); static String get(String region, String vhdName); }
CustomVMImageNameProvider { public static String get(String region, String vhdName) { String name = vhdName + DELIMITER + region.toLowerCase().replaceAll("\\s", ""); if (name.length() > NAME_MAXIMUM_LENGTH) { int diff = name.length() - NAME_MAXIMUM_LENGTH; int calculatedEndIndexOfVhdName = vhdName.length() - diff; name = vhdName.substring(0, calculatedEndIndexOfVhdName) + '-' + region.toLowerCase().replaceAll("\\s", ""); } return name; } private  CustomVMImageNameProvider(); static String get(String region, String vhdName);  }