void TestFileSystemInfo_SetAttributes() { // Improve code coverage on SCXFileSystemInfo #if defined(SCX_UNIX) SCXFileSystem::Attribute readable = SCXFileSystem::eUserRead; SCXFileSystem::Attribute writable = SCXFileSystem::eUserWrite; #else SCXFileSystem::Attribute readable = SCXFileSystem::eReadable; SCXFileSystem::Attribute writable = SCXFileSystem::eWritable; #endif SCXFileInfo fi(m_path1); SCXFileSystem::Attributes attrRO, attrRW; attrRO.insert(readable); attrRW.insert(readable); attrRW.insert(writable); // Test SCXFileSystemInfo::SetAttributes and SCXFileSystemInfo::isWritable (and make sure it's right!) fi.SetAttributes(attrRO); CPPUNIT_ASSERT(! fi.isWritable()); CPPUNIT_ASSERT(fi.GetAttributes().count(writable) == 0); fi.SetAttributes(attrRW); fi.Refresh(); CPPUNIT_ASSERT(fi.isWritable()); CPPUNIT_ASSERT(fi.GetAttributes().count(writable) != 0); // Create a new "junk" object to test directory - test SCXFileSystemInfo::GetDirectoryPath // (Use operator += to add a filename to pick up an additional test of that operator) SCXFilePath fbad = fi.GetDirectoryPath(); fbad += L"file"; fbad += L".txt"; fbad.SetDirectory(L"/bogus/directory/path"); #if defined(SCX_UNIX) CPPUNIT_ASSERT(fbad.GetDirectory() == L"/bogus/directory/path/"); CPPUNIT_ASSERT(fbad.Get() == L"/bogus/directory/path/file.txt"); #else CPPUNIT_ASSERT(fbad.GetDirectory() == L"\\bogus\\directory\\path\\"); CPPUNIT_ASSERT(fbad.Get() == L"\\bogus\\directory\\path\\file.txt"); #endif // Original path was created without directory - test SCXFileSystemInfo::GetOriginalPath CPPUNIT_ASSERT(fi.GetOriginalPath().GetDirectory() == L""); CPPUNIT_ASSERT(fi.GetFullPath().GetDirectory() != L""); }
/** Read a simple XML file to find the locations of the both the Admin and Managed servers for a WebLogic 11g R1 installation. Example: <?xml version="1.0" encoding="UTF-8"?> <domain ...> <name>base_domain</name> <domain-version>10.3.2.0</domain-version> <security-configuration ...> ... </security-configuration> <server> <name>AdminServer</name> <ssl> <name>AdminServer</name> <enabled>true</enabled> <listen-port>7012</listen-port> </ssl> <machine>new_UnixMachine_1</machine> <listen-port>7011</listen-port> <listen-address/> </server> <server> <name>new_ManagedServer_1</name> <ssl> <name>new_ManagedServer_1</name> <enabled>true</enabled> <listen-port>7513</listen-port> </ssl> <machine>new_UnixMachine_1</machine> <listen-port>7013</listen-port> <listen-address/> </server> <embedded-ldap> <name>base_domain</name> <credential-encrypted>{AES}RVX+Cadq8XJ5EvV7/1Ta2qGZrJlxve6t5CEa2A9euGUkYOMDTAwAqytymqDBS00Q</credential-encrypted> </embedded-ldap> <configuration-version>10.3.2.0</configuration-version> <machine xsi:type="unix-machineType"> <name>new_UnixMachine_1</name> <node-manager> <name>new_UnixMachine_1</name> <listen-address>localhost</listen-address> <listen-port>5566</listen-port> </node-manager> </machine> <admin-server-name>AdminServer</admin-server-name> </domain> \param[in] domainDir Directory of the domain (needed for build the path to the server \param[in] configXml File object of the XML file to open. \param[out] instances vector that will contain the list of server instances for the given domain. */ void WebLogicFileReader::ReadConfigXml( const SCXFilePath& domainDir, const SCXFilePath& configXml, vector<SCXHandle<AppServerInstance> >& instances) { SCX_LOGTRACE(m_log, L"WebLogicFileReader::ReadConfigXml"); SCX_LOGTRACE(m_log, wstring(L"WebLogicFileReader::ReadConfigXml() - "). append(L"Reading the file: ").append(configXml.Get())); string xml; try { SCXHandle<istream> reader = OpenConfigXml(configXml.Get()); GetStringFromStream(reader, xml); XElementPtr domainNode; XElement::Load(xml, domainNode); if (domainNode->GetName() == WEBLOGIC_DOMAIN_XML_NODE) { string version; ReadConfigXmlForVersion(domainNode, version); string adminServerName; ReadConfigXmlForAdminServerName(domainNode, adminServerName); XElementList serverNodes; domainNode->GetChildren(serverNodes); for (size_t index = 0; index < serverNodes.size(); ++index) { if (serverNodes[index]->GetName() == WEBLOGIC_SERVER_XML_NODE) { bool isAdminServer = false; bool isSslEnabled = false; string name = ""; string httpPort = ""; string httpsPort = ""; XElementList childNodes; serverNodes[index]->GetChildren(childNodes); for (size_t j = 0; j < childNodes.size(); ++j) { /* * <server> * <name>new_ManagedServer_1</name> * <ssl> * <name>new_ManagedServer_1</name> * <enabled>true</enabled> * <listen-port>7513</listen-port> * </ssl> * <machine>new_UnixMachine_1</machine> * <listen-port>7013</listen-port> * <listen-address/> * </server> * */ if (childNodes[j]->GetName() == WEBLOGIC_NAME_XML_NODE) { name = childNodes[j]->GetContent(); isAdminServer = adminServerName == name; } else if (childNodes[j]->GetName() == WEBLOGIC_SSL_XML_NODE) { ReadConfigXmlForSslInformation( childNodes[j], isSslEnabled, httpsPort); } else if (childNodes[j]->GetName() == WEBLOGIC_LISTEN_PORT_XML_NODE) { httpPort = childNodes[j]->GetContent(); } } /* * Having found the server node, * read the children */ wstring wideName = StrFromUTF8(name); SCXFilePath pathOnDisk; pathOnDisk.SetDirectory(domainDir.Get()); pathOnDisk.AppendDirectory(WEBLOGIC_SERVERS_DIRECTORY); pathOnDisk.AppendDirectory(wideName); if (DoesServerDirectoryExist(pathOnDisk)) { SCX_LOGTRACE(m_log, wstring(L"WebLogicFileReader::ReadConfigXml() - "). append(L"Adding instance for ID='").append(pathOnDisk.Get()). append(L"'")); // when the HTTP port is not set for the AdminServer, // default to the default weblogic HTTP port (i.e. 7001) wstring wideHttpPort = StrFromUTF8(httpPort); if(isAdminServer && L"" == wideHttpPort) { wideHttpPort = DEFAULT_WEBLOGIC_HTTP_PORT; } // when the HTTPS port is not set, default to // the default HTTPS port (i.e. 7002) wstring wideHttpsPort = StrFromUTF8(httpsPort); if(L"" == wideHttpsPort) { wideHttpsPort = DEFAULT_WEBLOGIC_HTTPS_PORT; } wstring wideVersion = StrFromUTF8(version); SCXHandle<AppServerInstance> instance( new WebLogicAppServerInstance ( pathOnDisk.GetDirectory())); instance->SetHttpPort(wideHttpPort); instance->SetHttpsPort(wideHttpsPort); instance->SetIsDeepMonitored(false, PROTOCOL_HTTPS); instance->SetIsRunning(false); instance->SetVersion(wideVersion); instance->SetServer( isAdminServer ? WEBLOGIC_SERVER_TYPE_ADMIN : WEBLOGIC_SERVER_TYPE_MANAGED); instances.push_back(instance); } else { SCX_LOGTRACE(m_log, wstring(L"WebLogicFileReader::ReadConfigXml() - "). append(L"The directory (").append(pathOnDisk.Get()). append(L") does not exist on disk, ignoring this instance")); } } } } } catch (SCXFilePathNotFoundException&) { SCX_LOGERROR(m_log, wstring(L"WebLogicFileReader::ReadConfigXml() - "). append(m_installationPath).append(L" - Could not find file: "). append(configXml.Get())); } catch (SCXUnauthorizedFileSystemAccessException&) { SCX_LOGERROR(m_log, wstring(L"WebLogicFileReader::ReadConfigXml() - "). append(m_installationPath).append(L" - not authorized to open file: "). append(configXml.Get())); } catch (XmlException& x) { SCX_LOGERROR(m_log, wstring(L"WebLogicFileReader::ReadConfigXml() - "). append(m_installationPath).append(L" - Could not load XML from file: "). append(configXml.Get())); } }