headers.addHeader("Opt",
"http://www.w3.org/1999/06/24-CCPPexchange;ns=19");
headers.addHeader("13-profile", "http://test13.com");
headers.addHeader("19-profile", "http://test19.com");
final DeviceIdentificationResult identificationResult =
DevicesHelper.getDevice(connectionMock, headers, accessorMock, null);
final Device device = identificationResult.getDevice();
// it doesn't matter which device is returned
assertTrue(device == deviceMock2a || device == deviceMock2b);
// identificationResult.getHeaderNamesUsed() contains the headers used
// for NN-profile check
final Collection headerNamesUsed =
identificationResult.getHeaderNamesUsed();
assertTrue(headerNamesUsed.contains("Opt"));
// must contain at least one *-profile header
String profileHeaderName = null;
for (Iterator iter = headerNamesUsed.iterator(); iter.hasNext(); ) {
final String headerName = (String) iter.next();
if (headerName.endsWith("-profile")) {
profileHeaderName = headerName;
}
}
assertNotNull(profileHeaderName);
assertTrue(profileHeaderName.equals("13-profile") ||
profileHeaderName.equals("19-profile"));
//now try it again with different Opt header order
headers = HttpFactory.getDefaultInstance().createHTTPHeaders();
// initial user agent string
headers.addHeader("User-Agent", "ua string");
// NN-profile header
headers.addHeader("Opt",
"http://www.w3.org/1999/06/24-CCPPexchange;ns=19");
headers.addHeader("Opt",
"http://www.w3.org/1999/06/24-CCPPexchange;ns=13");
headers.addHeader("13-profile", "http://test13.com");
headers.addHeader("19-profile", "http://test19.com");
final DeviceIdentificationResult identificationResult2 =
DevicesHelper.getDevice(connectionMock, headers, accessorMock, null);
// identified the same device
assertTrue(device.getName().equals(
identificationResult2.getDevice().getName()));
// used the same headers to identify the device
assertEquals(
headerNamesUsed, identificationResult2.getHeaderNamesUsed());
}