otatest.java
来自「cqME :java framework for TCK test.」· Java 代码 · 共 926 行 · 第 1/3 页
JAVA
926 行
protected Hashtable getAppRequestHeaders() { return otaServer.getAppRequestHeaders(); } /** * Requests the handler to remove all installed suites. Returns * Status.passed only if the provided Status is passed and the removal is * successful. If the provided status is not passed, it always be * returned. * <p> * The returned status can be considered as an overall status. * * @param ret * Current status. * @return overall status. */ protected Status removeAll(Status ret) { Status remStatus = handler.removeAll((String) null); if (ret != null && ret.isPassed()) { return remStatus; } else { return ret; } } /** * Requests the handler to install the suite with the specified name, * expecting that the installation should fail. Before that, instructs the * OTA server to restrict GET requests to "applicationName.jar" and * "applicationName.jad" only (if the provided application name is * "applicationName"), and sets additional attributes. * * @param attr * Additional attributes to set. * @param name * Application suite's name. * @param comment * Comments to be presented during installation process, or * <code>null</code> if there is no need for custom comments. * @return Overall status of the operation. * @see OTAHandler#installNegative(String, String) */ protected Status installNegative(Attributes attr, String name, String comment) { String JADNAME = name + ".jad"; String JARNAME = name + ".jar"; otaServer.setAdditionalAttributes(attr, JADNAME); String[] allowedNames = new String[]{JADNAME, JARNAME}; otaServer.setURLs(allowedNames); String url = address + "/" + JADNAME; Status ret = handler.installNegative(url, comment); if (ret != null && !ret.isPassed()) { handler.removeAll((String) null); } return ret; } /** * Requests the handler to install the suite with the specified name, * expecting that the installation should fail and the specified * installation code is returned. * <p> * Before that, instructs the OTA server to restrict GET requests to * "applicationName.jar" and "applicationName.jad" only (if the provided * application name is "applicationName"), and sets additional attributes. * <p> * Overall status depends on the installation code to be equal to the * given expectedCode. If codes do not match, the failed status will be * returned. * * @param attr * Additional attributes to set. * @param name * Application suite's name. * @param comment * Comments to be presented during installation process, or * <code>null</code> if there is no need for custom comments. * @param expectedCode * Expected installation status code. * @return Overall status of the operation. * @see OTAHandler#installNegative(String, String) */ protected Status installNegative(Attributes attr, String name, String comment, String expectedCode) { // Set list of midlets(jars) and jads that can be downloaded String JADNAME = name + ".jad"; String JARNAME = name + ".jar"; otaServer.setAdditionalAttributes(attr, JADNAME); String[] allowedNames = new String[]{JADNAME, JARNAME}; otaServer.setURLs(allowedNames); String url = address + "/" + JADNAME; ref.println("Installing " + JARNAME + "\n"); Status ret = handler.installNegative(url, comment); if (ret != null && ret.isPassed()) { ref.println("Waiting for notification"); long now = System.currentTimeMillis(); long end = now + timeout; synchronized (otaServer) { while (!otaServer.getInstallNotification(name, expectedCode)) { try { otaServer.wait(100); now = System.currentTimeMillis(); if (now > end) { return noCodeReceived(expectedCode); } } catch (InterruptedException ie) { ie.printStackTrace(log); return Status.failed("Unexpected " + ie); } } } } if (ret != null && !ret.isPassed()) { ref.println("The MIDlet suite(s) should not be installed. " + "Removing the midlet\n"); Status s = handler.removeAll((String)null); if (s == null || !s.isPassed()) ref.println("Could not remove all midlets\n"); } return ret; } /** * Requests the handler to install the suite with the specified name. * Before that, instructs the OTA server to restrict GET requests to * "applicationName.jar" and "applicationName.jad" only (if the provided * application name is "applicationName"), and sets additional attributes. * * @param attr * Additional attributes to set. * @param name * Application suite's name. * @param comment * Comments to be presented during installation process, or * <code>null</code> if there is no need for custom comments. * @return Overall status of the operation. */ protected Status install(Attributes attr, String name, String comment) { ref.println("Installing " + name + "\n"); String JADNAME = name + ".jad"; String JARNAME = name + ".jar"; otaServer.setAdditionalAttributes(attr, JADNAME); String[] allowedNames = new String[]{JADNAME, JARNAME}; otaServer.setURLs(allowedNames); String url = address + "/" + JADNAME; Status ret = handler.install(url, comment); if (ret == null || !ret.isPassed()) { ref.println("Could not install midlet suite from " + url); } return ret; } protected Status noCodeReceived(String expectedCode) { return Status.failed("No installation notification with code " + expectedCode + " received in " + timeout/1000 + " seconds"); } /** * @deprecated The method is here for compatibility reasons. * Use {@link #runWithNotification(String, String, String)} where possible. */ public Status runWithNotification(String name, String comment) { return runWithNotification((String) null, name, comment); } /** * Requests the handler to execute the suite with the specified name, * installed from the given URL, providing standard prompt with additional * specified comment line. * * @param appURL * The URL of the application to be ran. * @param name * Application suite's name. * @param comment * Comment to be presented, or * <code>null</code> if there is no need for custom comment. * @return Overall status of the operation. */ public Status runWithNotification( String appURL, String name, String comment) { return runWithNotification( appURL, name, comment, (String[]) null, null); } /** * Requests the handler to execute the suite with the specified name, * installed from the given URL, providing full user-specified interactive * interface. * * @param appURL * The URL of the application to be ran. * @param name * Application suite's name. * @param comments * Comments to be presented. * @param question * The question to ask while preparing for application * execution. * @return Overall status of the operation. */ public Status runWithNotification(String appURL, String name, String[] comments, String question) { return runWithNotification( appURL, name, (String) null, comments, question); } private Status runWithNotification(String appURL, String name, String comment, String[] comments, String question) { resetNotifications(); status = null; operation = "run"; this.name = name; NotifySender sender = new NotifySender(); sender.start(); try { Status handlerStatus; if (comments != null) { handlerStatus = handler.runWithNotification(appURL, name, comments, question); } else { handlerStatus = handler.runWithNotification(appURL, name, comment); } if (handlerStatus != null && !handlerStatus.isPassed()) { return handlerStatus; } return (status != null) ? status : handlerStatus; } finally { sender.stop(); } } protected Status installNegativeWithNotification(Attributes attr, String name, String comment) { resetNotifications(); status = null; operation = "installNegative1"; this.name = name; String JADNAME = name + ".jad"; String JARNAME = name + ".jar"; otaServer.setAdditionalAttributes(attr, JADNAME); String[] allowedNames = new String[]{JADNAME, JARNAME}; otaServer.setURLs(allowedNames); String url = address + "/" + JADNAME; NotifySender sender = new NotifySender(); sender.start(); try { Status handlerStatus = handler.installNegativeWithNotification( url, comment); if (handlerStatus != null && !handlerStatus.isPassed()) { return handlerStatus; } return (status != null) ? status : handlerStatus; } finally { sender.stop(); } } /** * Requests the handler to install the suite with the specified name, * expecting that the installation should fail and the specified * installation code is returned. * <p> * Before that, instructs the OTA server to restrict GET requests to * "applicationName.jar" and "applicationName.jad" only (if the provided * application name is "applicationName"), and sets additional attributes. * <p>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?